while ループで結果を表示する際に、これらのコード スニペットがどのように異なるかについて混乱しています。コードの最初のスニペットは完全に機能しますが、2 番目のコードでは結果が表示されますが、無限ループで表示され、結果が繰り返されます。誰かが私に理由を説明できますか?
$stmt = $db_conn->prepare($sql);
$stmt->execute(array("Lorna", 3));
while($result = $stmt->fetch()){
echo $result["name"] . "<br />" . $result["description"] . "<br />";
}
$stmt->fetch() を $data という変数に入れ、$stmt->fetch() を while ループに入れる代わりにこれを渡そうとすると、無限ループが発生します。
$stmt = $db_conn->prepare($sql);
$stmt->execute(array("Lorna", 3));
$data = $stmt->fetch();
while($result = $data){
echo $result["name"] . "<br />" . $result["description"] . "<br />";
}
前もって感謝します!