Forum Moderators: coopster
I have a script which I use to schedule events. It does so successfully. I am at the point now where the basic functionality is set, and I am coding added features.
The newest feature I am trying to add (and it's driving me nuts!) is being able to select attendees for the events and add them to the db entry for the event. I have already set up a table which holds the pertinent information about the attendees, now I just need to be able to add them to the events. The attendees each have an ID.
Questions.. What's the best way to accomplish this? The # of attendees varies from event to event, but never more than 12. I don't mind storing each attendee by ID in the event db, but even then, I am not sure how to go about it.
Help?!
To write array of attendees you can implode the array, and to read it from db you can explode it, or even you can store their names there, so you won't have to read the info about them everytime you want to retrieve the list.
This might not be the best method, but it should work. If you want me to write an exemplary script, just say so.
Best regards
Michal Cibor
<?php
$attendees = array('John Brown', 'Andre Wilkinson', 'Mary Smith', 'Abu Mhadha');//you will get this in some another way$str = implode(",", $attendees);//this is a string: "John Brown, Andre..."
$conn = mysql_connect("host", "user", "pass") or die(mysql_error());
mysql_select_db("dbname", $conn) or die(mysql_error());$sql = "UPDATE table SET attendees='$str' WHERE event='2005-12-12'";
mysql_query($sql) or die(mysql_error());
?>
<?php
$sql = "SELECT attendees FROM table WHERE event='2005-12-12'";
mysql_....//connect
$ask = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($ask))
{
while($answer = mysql_fetch_array($ask))
{
$attendees = $answer['attendees'];
$array = explode(",",$attendees);//you get an array back
}
}?>