从循环中停止WHILE循环 [英] Stop WHILE loop from looping
本文介绍了从循环中停止WHILE循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我正在尝试显示数据库中的项目,但是while循环不断循环。
无论如何我可以阻止它循环每个人周围?
请参阅下面的代码。
我尝试了什么:
Hi
I am trying to display items from a database, however the while loop keeps looping around.
Is there anyway i can stop it looping around each one?
See code below.
What I have tried:
<?php
$1 = ("cheese");
$2 = ("yoghurt");
$3 = ("egg");
$dbQuery=$conn->prepare("select * from Results");
$dbQuery=$conn->prepare("select * from Food where Keyword = '$1'");
$dbQuery->execute();
echo $dbQuery->rowCount()."\n";
while ($dbRow=$dbQuery->fetch(PDO::FETCH_ASSOC)) {
if ($1 = '1') {
echo "<br><br>".$dbRow["Name"]."<br>"."<br><img src=/".$dbRow['Picture']."' width='150' height='150' float='left'/>"."".$dbRow["Instructions"]."\n";
} else {
echo "";
}
$dbQuery=$conn->prepare("select * from Food where Keyword = '$2'");
$dbQuery->execute();
if ($2 = '1') {
echo "<br><br>".$dbRow["Name"]."<br>"."<br><img src=/".$dbRow['Picture']."' width='150' height='150' float='left'/>"."".$dbRow["Instructions"]."\n";
} else {
echo "";
}
$dbQuery=$conn->prepare("select * from Food where Keyword = '$3'");
$dbQuery->execute();
if ($3 = '1') {
echo "<br><br>".$dbRow["Name"]."<br>"."<br><img src=/".$dbRow['Picture']."' width='150' height='150' float='left'/>"."".$dbRow["Instructions"]."\n ";
} else {
echo "";
}
}
?>
推荐答案
1 =(cheese);
1 = ("cheese");
2 =(yoghurt);
2 = ("yoghurt");
3 =(egg);
3 = ("egg");
这篇关于从循环中停止WHILE循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文