我有這樣的foreach循環:PHP - foreach循環只運行一個
$d=$dbh->prepare("SELECT * FROM users_rented WHERE since <= unix_timestamp(CURRENT_TIMESTAMP - INTERVAL 14 day) AND clicks_last <= unix_timestamp(CURRENT_TIMESTAMP - INTERVAL 14 day)");
$d->execute();
$array = array();
foreach ($d as $data) {
$array[] = $data['id'];
#print_r($new_array);
$userToRecycleFor = $data['user_by'];
$outcome = $rentedrefs->_recycleMulti(0, $userToRecycleFor, $array, 1);
}
的$d
查詢有2406個結果時,我在MySQL數據庫中運行它。
foreach
循環僅在每個頁面上運行1次刷新。因此,而不是更新所有2406個用戶(按照SQL查詢),它每更新一次只更新一次。
我在做什麼錯?
您應該獲取結果。有人與你有完全相同的問題 - > http://stackoverflow.com/questions/16916036/fetch-in-pdo-gets-only-one-result – pbaldauf 2014-11-02 16:23:30
你正在尋找'PDO :: fetch' http:// php.net/manual/en/pdostatement.fetch.php – Victory 2014-11-02 16:23:36