SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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']; ?>&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>
    </table><?php } while($rsEvent = mysql_fetch_assoc($event_query)) ?>
    </body>
    </html>

    Thank You.
    Jordan Smith.
    Last edited by nzol; Feb 2, 2010 at 15:08. Reason: Added Code

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    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 Code:
    <?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>

  3. #3
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I assume your table is not actually named table. I didn't change your query.

  5. #5
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah yes, I had to change the table to the correct name.

    Thank You very, very much.

    Have a great Day.

    Jordan Smith


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •