Check if final record?
I am using mysql_开发者_StackOverflow中文版fetch_array and I want to check if it's the final record. How can I do this?
EDIT
Jumped the gun the first time.
Use mysql_num_rows to count the rows before looping. Simple for loop example:
$numrows = mysql_num_rows($resource);
for ($i = 1; $i <= $numrows; $i++) {
$row = mysql_fetch_array($resource);
if ($i == $numrows) {
// last record
}
}
There might be a better way, but if you neeeed to know if it's the final record you could get the row count beforehand and then increment a counter in the loop and test to see if it equals the row count.
精彩评论