0

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?

2 Answers 2

1

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

1
  • 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. Commented Feb 7, 2009 at 2:25
1

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++;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.