-1

我需要循环几次查询的结果。在第一个循环之后,由于指针位于底部,我无法再次查看结果。我怎样才能让它回到顶部?我不想再次运行查询,因为这只会消耗更多资源并返回相同的结果。

$stmt = $conn->prepare("SELECT * FROM customers");
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();

//This kind of loop will repeat elsewhere in the code
while($row = $stmt->fetch()){ 
//Do something here
}
4

1 回答 1

2
while($row = $stmt->fetch()){ 
    $rows[] = $row;  //use $rows later
    //Do something here with $row
}
于 2013-10-11T21:08:32.540 回答