Skip to content
Advertisement

Looping through PHP prepared SQL statement result twice

I’m trying to loop through a SQL result in PHP twice, and I am not succeeding. I have tried to use mysqli data seek, but this does not work.

Here is what I have tried so far:

my-new-file.php

JavaScript

If I do the code below, I get the desired result:

my-newer-file.php

JavaScript

It seems like a waste of resources/inefficient to have to run the execute and bind_result statements twice. I was under the assumption that mysqli data seek would reset the pointer to 0, and I could loop through the query again.

This is probably just an oversight on my part. What am I doing wrong?

Advertisement

Answer

Try using $result->store_result(); right after the very first $result->execute().

Seemed to do the trick for me.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement