Page 1 of 1

Can't get more than one DB entry to display

Posted: Thu Apr 14, 2011 9:33 pm
by jasonv
Hello,
I took over a site from a non-profit organization recently and have been looking for a way to display more than one reservation from a specific MySQL DB.
The file accesses the DB just fine, but will only return one entry. I am having trouble deciphering the previous programmers variable input and can't see where the limit to only one item being displayed is occurring. If someone would be willing to help, that would be great.

Here is the pertinent code info.

Code: Select all

<body id="b">
$today = time();

if($_GET['dl'] == "0"){
$selected_month = date("F", $today);
}else{
$selected_month = $_GET['dl'];
}
/* mm-dd-yyyy */

                 
$query_tour_list = "SELECT * FROM pf_reservations WHERE  pf_reservations.month = '$selected_month' AND pf_reservations.year = '2011' ORDER BY pf_reservations.date ASC";
$tour_list = mysql_query($query_tour_list, $sql) or die(mysql_error());
$row_tour_list = mysql_fetch_assoc($tour_list);
$totalRows_tour_list = mysql_num_rows($tour_list);

if (mysql_num_rows($tour_list) >= 0) {

$pid = mysql_result($tour_list, 0, 'date');
 
 
}

?>

<div style="font-size:20px; padding:10px;">harvestfarm.net admin</div>
<div id="wrapper">
<table border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td id="menu_td" valign="top"><?php include "../includes/left_menu.php"; ?>
    </td>
    <td id="body_td" valign="top" style="background-color:#FFFFFF;"><br />
      <div id="page_content">
        <div id="month_link"> <a href="?dl=April">April</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="?dl=May">May</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="?dl=June">June</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="?dl=July">July</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="?dl=August">August</a>&nbsp;&nbsp;&nbsp;&nbsp;<!-- <a href="?dl=September">September</a> --></div>
        <div style="font-size:24px; padding:10px 5px 5px 5px;"><?php echo $selected_month; ?>&nbsp;(<?php echo $totalRows_tour_list; ?>&nbsp;tours)</div>
<?php if($_GET[m] == "tc"){ ?><div style="font-size:12px; color:#FF0000; padding:0px 0px 10px 5px;">Tour closeout successful.</div><?php } ?>
<?php if($_GET[m] == "tu"){ ?><div style="font-size:12px; color:#FF0000; padding:0px 0px 10px 5px;">Tour info updated.</div><?php } ?>
        
        <?php if ($pid != "0"){

do { ?>
        <div style="border:1px solid #CCCCCC; width:300px; float:left; margin:1px 300px 1px 1px; <?php if(($row_tour_list['date'] < $today) && ($row_tour_list['payment'] != "0")){ ?> color:#999999; <?php } else if(($row_tour_list['date'] < $today) && ($row_tour_list['payment'] == "0")){ ?> color:red; <?php }else{ ?> color:#000000; <?php } ?>">
          <div style="float:left; color:#FFFFFF; background-color:#000099; font-size:18px; padding:3px; border:4px solid #FFFFFF; text-align:center;"><?php echo date("j", $row_tour_list[date]); ?><div style="font-size:10px;"><?php echo date("D", $row_tour_list[date]); ?></div></div>
          <div style="float:left; background-color:#FFFFFF; padding:3px;">
            <?php if ($row_tour_list['organization'] == ""){echo $row_tour_list[contact_name];} else {echo $row_tour_list[organization]; } ?>
            <br />
            <?php $grpsize = $row_tour_list[students] + $row_tour_list[teachers] + $row_tour_list[parents]; ?>
            Group Size: <?php echo $grpsize; ?><br />
            <?php echo $row_tour_list[lunch]; ?>&nbsp;Pizza Lunches</div>

Re: Can't get more than one DB entry to display

Posted: Thu Apr 14, 2011 9:51 pm
by incubi
Hi,
I've had to undo some messed up code too so I know what you're getting into.
Start by pulling out the query code i.e. no HTML into a new file. Do the query and view the results with simple print or echo statements. Also undo the mixing of the html and the php create a function with the html in it using print or echo. Well, that's the best way I've found anyway. Next for testing anyway use while loops for the query.

Also maybe this will help.

http://php.net/manual/en/control-structures.while.php

http://www.macronimous.com/resources/wr ... sy_php.asp

Lee