Having a weird problem with mysql_fetch_array ()

Why can't I get inside the while in the getCustomers() function?

 $stores = $bl->getStoresForGuide($gID); //Returns 6 stores $storelist = getStoreList($stores); //Generate the HTML for the store list $brandlist = getCustomers($stores); //Generate the HTML for brand list function getStoreList($stores) { while ($row = mysql_fetch_array($stores)) { // Do stuff } //return result } function getCustomers($stores) { echo mysql_num_rows($stores); //Outputs 6 while ($row = mysql_fetch_array($stores)) { echo "test "; // Outputs nothing } // Return some result } 
+4
source share
2 answers

You loop twice. When you first start, you will reach the end, and the pointer will not reset before you close again.

If you are sure you want to do this, look at mysql_data_seek and find the beginning of the result. Otherwise, I would recommend just saving the results and iterating over the array.

+5
source

First you call getStoreList , and then when you call getCustomers , $stores already got all their rows.

0
source

Source: https://habr.com/ru/post/1299385/


All Articles