While-loop misses out on the last row in SQL database table?
Posted: Sun May 03, 2009 1:00 pm
Hi all!
I have made a really simple "newsfeed" on a webpage, which seems to be working fine, except that it doesn't display the last added row. I have to add another, blank row of data in the database in order for it to show the previous (last) one.. any ideas on why this happens?
Things I've tried:
* Taking away the LIMIT
* Changing LIMIT to only 4
* Changing ORDER to ASC
...but that's all I can think of with my VERY limited knowledge of PHP/MySQL.. Any help is much appreciated!
Best Regards // Leif
Part of my code:
I have made a really simple "newsfeed" on a webpage, which seems to be working fine, except that it doesn't display the last added row. I have to add another, blank row of data in the database in order for it to show the previous (last) one.. any ideas on why this happens?
Things I've tried:
* Taking away the LIMIT
* Changing LIMIT to only 4
* Changing ORDER to ASC
...but that's all I can think of with my VERY limited knowledge of PHP/MySQL.. Any help is much appreciated!
Best Regards // Leif
Part of my code:
Code: Select all
<?php
"SELECT *
FROM `tip`
ORDER BY `tip`.`id` DESC
LIMIT 0,4
");
$row = mysql_fetch_array($result);
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<span class='header'>" . $row['header'] . "</span>" . "<p>" . $row['text'] . "</p>" . "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";
echo "<p>Added by " . "<em>". $row['name'] . "</p></em><br>";
}
mysql_close($con);
?>