Recursively call mysql_fetch_array?

Sorry if this is short but chrome just swallowed my post.

Tyring to call mysql_fetch_array recursively, cant be bothered to paste and format my code again. Basically, i have my mysql_query statment outside the recursive function and mysql_fetch_array inside, the idea being that mysql_fetch_array only uses the selection that has already been retrived and dosent have to dive back into the DB every time.

The problem is that mysql_fetch_array is not working more than once, i tryed reseting the pointer but that dident do it. PHP dosent seem to have any functions to return a row so i cant do it without mysql_fetch_array as far as i can see.

Thanks,
Nick

Your probably looking for something like this:

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    // Do something with each row here
}

It’ll go through each row of the result set in turn until there are no more rows remaining in the result set.

Hey, thanks for havin a look, i am using that while but it only works once, when i call the function again, it does not work, the while dosent execute.

Are you resetting the internal pointer?


$res = mysql_query('SELECT foo FROM table;');

while($row = mysql_fetch_assoc($res)){
  echo $row['foo'];
}

mysql_data_seek($res, 0);

while($row = mysql_fetch_assoc($res)){
  echo $row['foo'];
}

I think you’re going to have to post some code, again. :slight_smile: