MySQL dynamic select and display on screen

I have been making an RSVP service for my parents upcomming wedding. I have been sucessful with all the other codes and scripts but i am having trouble with something. On a viewguests.php page, i want to modify this so my mum can go on and see a list of people who have responded through a form that posts data to the table. At the moment, I have 4 test people in the table of guests, and when i go to viewguests.php?eventid=12345 (the php page to view the guests) it only displays one result. (When a guest responds they type the event id (field: eventid) and that goes in to the table). So what i want to do is have all of the rows in the table with the event id 12345 show up, not just one result.

If anyone can help me, I will be very happy.

Here is the script i already have:

<?php

$dbh = mysql_connect(“localhost”,“username”,“passwork”) or die(mysql_error());
mysql_select_db(“database”);

$eventid = $_GET[‘eventid’];

$event_sql = “SELECT * FROM table WHERE eventid=$eventid LIMIT 0, 30”;
$event_query = mysql_query($event_sql) or die(mysql_error());
$rsEvent = mysql_fetch_assoc($event_query);
while($result = mysql_fetch_array($event_query));

?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1” />
<title>Untitled Document</title>
</head>

<body>
<?php do { ?>
<table width=“800” border=“1” cellspacing=“0” cellpadding=“0”>
<tr>
<td width=“133”><?php echo $rsEvent[‘id’]; ?> </td>
<td width=“133”><?php echo $rsEvent[‘name’]; ?></td>
<td width=“133”><?php echo $rsEvent[‘email’]; ?></td>
<td width=“133”><?php echo $rsEvent[‘phone’]; ?></td>
<td width=“133”><?php echo $rsEvent[‘notes’]; ?></td>
</tr>
</table><?php } while($rsEvent = mysql_fetch_assoc($event_query)) ?>
</body>
</html>

Thank You.
Jordan Smith.

while($result = mysql_fetch_array($event_query));

This is a loop with no body, it fetches every row out of the result set and does nothing with it. Then you display the last row it fetched in your HTML below.

Modified:

<?php

$dbh = mysql_connect("localhost","username","passwork") or die(mysql_error());
mysql_select_db("database");

$eventid = (int)$_GET['eventid'];

$event_sql = "SELECT * FROM table WHERE eventid=$eventid LIMIT 0, 30";
$result = mysql_query($event_sql) or die(mysql_error());

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<table width="800" border="1" cellspacing="0" cellpadding="0">
<?php while ($rsEvent = mysql_fetch_array($result)) { ?>
	<tr>
	<td width="133"><?php echo $rsEvent['id']; ?>&nbsp;</td>
	<td width="133"><?php echo $rsEvent['name']; ?></td>
	<td width="133"><?php echo $rsEvent['email']; ?></td>
	<td width="133"><?php echo $rsEvent['phone']; ?></td>
	<td width="133"><?php echo $rsEvent['notes']; ?></td>
	</tr>
<?php } ?>
</table>
</body>
</html>

Hi Dan Grossman:

When I try it, it shows up with this:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘table WHERE eventid=96708’ at line 1

By The way, thanks for your help!

I assume your table is not actually named table. I didn’t change your query.

Ah yes, I had to change the table to the correct name.

Thank You very, very much.

Have a great Day.

Jordan Smith