Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've got a fairly standard while mysql_fetch_array statement in php, and I'm trying to figure out which row in the result set is being printed.

I figured this should be pretty simple, but I've put a fairly standard

$i=0;
$count=mysql_num_rows($getResults);
while($resultArray=mysql_fetch_array($getResults)){

$i++
if($i==$count){
echo "this is the last row";
}
}

but strangely, that isn't working. is there another way to find the last row?

share|improve this question

2 Answers 2

This worked for me. Your placement was a little different and you didnt have a semi-colon after $i++

$i=0;
$count=mysql_num_rows($result);
while($resultArray=mysql_fetch_array($result))
{
    if($i==$count-1)
    {
        "this is the last row";
    }
    $i++;
}
share|improve this answer
    
sorry yours worked fine, id check your query string –  Samuel Feb 7 '09 at 2:01

What you've got is correct (that is, it should be working): are you sure that there are more than 0 rows being returned?

share|improve this answer
    
Yup, more than 0 rows being returned, but I had screwed up my loop, so that last bit was running outside of the while loop. Sorry about that, my bad. –  pedalpete Feb 7 '09 at 2:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.