|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I'd like some advice on the design of a MySQL database that details an event and details about this event. Basically I have a table which lists time,date,location etc, but for each event recorded in this table there are up to 15 or so participants. What is the best way of storing and retrieving this data? Adding a field per participant to the table would contravene normalisation rules, but then if the participants are listed in another table, with a reference to the first table, how do you then doa SELECT to retrieve information about 1 event and all the participants in one single query? Any information much appreciate, thanks, Zammee |
|
#2
|
|||
|
|||
|
Your solution
I'd say the best way of accomplishing that task will be having one field that is named participants and it will store each person that can be delimited by a certain characater or characaters. For example: John Doe|Mary Jane|Bill Gates (the | is your delimiter) You could use anything, but don't use a space if you store people by full name.
Then you select that event from the table and then you will have your server side language break it up. With PHP you can use either explode() or split(). Using split() will allow you to use regular expressions. Or you can have a completely different table that stores the people by event ID. And you select the people involved in that event by the event ID using MySQL's WHERE clause. Hope this helps. Last edited by Brian Rosner : August 30th, 2002 at 04:10 PM. |
|
#3
|
|||
|
|||
|
Re: Multiple users per event
Quote:
You've got the right idea... The way you would select both tables is like this: SELECT events.name, users.name WHERE users.eventId = events.eventId That's just an idea... I'm not sure what you're table/field names are... But if you're confused and need help, let me know!
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#4
|
|||
|
|||
|
Thanks Frankie,
What I'd like to achieve is to retrieve PHP Code:
PHP Code:
A crude way of performing this might be PHP Code:
Kind regards, zammee |
|
#5
|
|||
|
|||
|
If I understand correctly, try this:
SELECT event.name, users.name WHERE users.eventid = event.eventid That will display all the users that correspond to a specific event. |
|
#6
|
|||
|
|||
|
Frank,
Sorry not to have made myself a bit clearer :- your method works of course, but you get one result row for each combination of event/user, so 2 events with 10 and 5 users each respectively would give 15 result rows. What I'd ideally like is to have one result row per event, each row including all the users as well as the name of the event, so that for the numbers above there would be 2 result rows, although I don't know how the columns would look - this is where I'm stuck This might not be a feasible proposition though, just let me know if I'm trying to do the impossible!! Thanks very much, zammee |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > Multiple users per event |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|