我有这样的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