tags:

views:

30

answers:

2

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
I don't think that answers the question. He's asking how to find if the subsequent fetch will return false.
wallyk
That's much better.
wallyk
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