为什么我无法进入 getCustomers()
函数中的 while
循环?
$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
}
最佳答案
你循环了两次。第一次循环时,您会到达终点,并且在您再次循环之前不会重置指针。
如果您确定要执行此操作,请查看 mysql_data_seek , 并寻找结果的开头。否则,我建议只存储结果并遍历数组。
关于php - mysql_fetch_array() 有一个奇怪的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2136863/