2010-01-26 65 views
4

爲什麼我不能進入循環中的getCustomers()函數?在mysql_fetch_array()有一個奇怪的問題

$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 
} 

回答

5

你正在循環兩次。第一次循環時,你會到最後,並且在你再次循環之前指針不會被重置。

如果您確定要這樣做,請查看mysql_data_seek,並尋找結果的開頭。否則,我建議只存儲結果並遍歷數組。

+0

謝謝。不知道。我把結果放在一個數組中,現在它工作正常。 – Steven 2010-01-26 01:46:29

0

您首先打電話getStoreList,然後等到您撥打getCustomers時,$stores已經取得了所有行。