Some people say you should not use mysql_fetch_assoc
more than one time, why is that?
e.g.: I want to display two tables one with users who paid for mem
Quote by Typer85 (link):
Please be advised that the resource result that you pass to this function can be thought of as being passed by reference because a resource is simply a pointer to a memory location.
Because of this, you can not loop through a resource result twice in the same script before resetting the pointer back to the start position.
For example:
The only solution to this is to reset the pointer to make it point at the first row again before the second code segment, so now the complete code will look as follows:
Of course you would have to do extra checks to make sure that the number of rows in the result is not
0
or elsemysql_data_seek
itself will returnfalse
and an error will be raised.Also please note that this applies to all functions that fetch result sets, including
mysql_fetch_row
,mysql_fetch_assos
, andmysql_fetch_array
.