Jump to content

while($row = mysql_fetch_array($result)) isn't returning final record


Recommended Posts

Hey all--

 

Here's the setup: I'm joining two tables and then using while($row = mysql_fetch_array($result)) to echo the resulting records into an HTML table.  But only 15 of the 16 records are showing up.  If I delete one record, I get 14 out of 15.  The one to not show up is always the latest record.

 

<?php

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("atsband", $con);
$query = "SELECT some fields of table 1 and table 2 FROM table 1 LEFT JOIN table 2 ON table 1.field = table 2.field WHERE date < NOW() ORDER BY date DESC";

if ($result = mysql_query($query, $con)) {
  if (mysql_num_rows($result)) {
    while($row = mysql_fetch_array($result)) {

echo "<table id='shows_past'><th>Date/Time</th><th>Venue</th><th>Location</th>";

while($row = mysql_fetch_array($result))
{
echo "an HTML table";
}

echo "</table>";

    }
  } else {
echo "Something went wrong.";
  }
}
else {
    
echo "The query failed.";
}



mysql_close($con);

?>

 

There's a similar question posted here, but I couldn't figure out if we were doing the same thing wrong (very new to MySQL and PHP by the way): http://www.phpfreaks.com/forums/index.php?topic=325757.msg1534001#msg1534001.

 

Thanks a bunch,

 

-Davis

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.