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]
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.