Jump to content

issue showing list of database entries - one is missing!...


scotch33

Recommended Posts

I am trying to list the rows from a table in my page using the following code.  The odd thing is that in the MYSQL admin there is sets 109 - 126 yet this code only shows sets 110 - 126.  There is no other code on the page that limits what is showing.  if i delete all entries and start again I am always showing one less in the mage than the admin is showing.  any ideas?  thanks!
John

[code]<?
echo "<table class='orderresults_table' border='0' cellspacing='0' cellpadding='0'>
<tr class='orderresults_heading'>
<td class='orderresults_inv'>Inv No</td>
<td class='orderresults_name'>Name</td>
<td class='orderresults_date'>Date</td>
<td class='orderresults_amount'>Amount</td>
<td class='orderresults_button'>More...</td>
</tr>";
while ($row = mysql_fetch_array($result)) {
echo "<tr class='orderresults_entry'>";
echo "<td class='orderresults_inv'>".$row['inv_no']."</td>";
echo "<td class='orderresults_name'>".$row['cust_name']." ".$row['cust_surname']."</td>";
echo "<td class='orderresults_date'>".$row['date']."</td>";
echo "<td class='orderresults_amount'>£".$row['order_total']."</td>";
echo "<td class='orderresults_button'><form id='detail' name='detail' method='post' action='detail.php'>
<input name='inv_no' type='hidden' value='".$row['inv_no']."' />
<input name='submit' type='submit' value='details' />
    </form></td>";
echo "</tr>";
}
echo"</table>"
?>[/code]
[code] $result =  mysql_query('SELECT * FROM dvd_orders');
if (!$result) {
exit('<p>error performing query:'.mysql_error().'</p>');
}
$row = mysql_fetch_array($result);
<h2>Orders Summary</h2>
<?
echo "<table class='orderresults_table' border='0' cellspacing='0' cellpadding='0'>
<tr class='orderresults_heading'>
<td class='orderresults_inv'>Inv No</td>
<td class='orderresults_name'>Name</td>
<td class='orderresults_date'>Date</td>
<td class='orderresults_amount'>Amount</td>
<td class='orderresults_button'>More...</td>
</tr>";
while ($row = mysql_fetch_array($result)) {
echo "<tr class='orderresults_entry'>";
echo "<td class='orderresults_inv'>".$row['inv_no']."</td>";
echo "<td class='orderresults_name'>".$row['cust_name']." ".$row['cust_surname']."</td>";
echo "<td class='orderresults_date'>".$row['date']."</td>";
echo "<td class='orderresults_amount'>£".$row['order_total']."</td>";
echo "<td class='orderresults_button'><form id='detail' name='detail' method='post' action='detail.php'>
<input name='inv_no' type='hidden' value='".$row['inv_no']."' />
<input name='submit' type='submit' value='details' />
    </form></td>";
echo "</tr>";
}
echo"</table>"
?>
[/code]
OK, there's your problem.

Right after your query you have:

$row = mysql_fetch_array($result);

Which grabs the first record from your result set. But before you ever use that data, you call this:

while ($row = mysql_fetch_array($result)) {

Which grabs the 2nd record from the result set. Just remove the first one and you should be fine.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.