Forum Moderators: coopster

Message Too Old, No Replies

Need some direction

Not sure how to accomplish this

         

BadGoat

6:29 pm on May 11, 2005 (gmt 0)

10+ Year Member



Hi,

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?!

mcibor

8:38 pm on May 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would do it so: I would store the attendees id in a string field separated by commas.

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

BadGoat

8:41 pm on May 11, 2005 (gmt 0)

10+ Year Member



mcibor: yes, please! I have never used implode, so it will be new to me.

Thank you!

mcibor

8:56 pm on May 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Writing the attendees to db:

<?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());
?>


Reading from db:
<?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
}
}?>

Hope this helps
Michal Cibor

BadGoat

8:59 pm on May 11, 2005 (gmt 0)

10+ Year Member



Thank you Michael, working on implementing it now!