"mysqli_fetch_assoc($result), pointer moves to the next record. is there any way to reset the pointer to the start of the query result?" Code Answer

5

so i was stuck with this problem at work today, and the only solution i initially found was to re-query, or use temporary copy of mysql result in a variable. neither of which were appealing.

there is a much simpler solution to this which is mysql_data_seek.

basic syntax is mysqli_data_seek(data,row)

so in this case you just do

mysqli_data_seek($result,0)
$row=mysqli_fetch_assoc($result);// will now return the first row.

in a similar way you could loop through it again too.

it works similarly with mysql_data_seek. hope it was helpful.

By Mahmoud Al-Qudsi on October 12 2022

Answers related to “mysqli_fetch_assoc($result), pointer moves to the next record. is there any way to reset the pointer to the start of the query result?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.