Why am I not able to get inside the while loop 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
}
You’re looping twice. The first time you loop, you get to the end, and the pointer isn’t reset before you loop again.
If you’re sure you want to do this, check out mysql_data_seek, and seek to the beginning of the result. Otherwise, I’d recommend just storing the results and iterating over the array.