I am using mysql_fetch_array and I want to check if it's the final record. How can I do this?
A:
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
}
}
Phil
2009-11-19 21:00:57
I don't think that answers the question. He's asking how to find if the subsequent fetch will return false.
wallyk
2009-11-19 21:03:16
That's much better.
wallyk
2009-11-19 23:53:24
A:
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.
Galen
2009-11-19 21:01:52