如何写一个条件,如果找不到那行呢?
我的代码
$resultt = mysql_query("SELECT * FROM objednavky WHERE kdo = '$kdo' and kdy = '$the_rday'");
while ($roww = mysql_fetch_array($resultt)) {
echo "<form method='post' action=''>
<label for='obb1'>Menu #1 </label>
<input type='text' name='obb1' value='$roww[3]' size='4'><br>
<label for='obb1'>Menu #2 </label>
<input type='text' name='obb2' value='' size='4'><br>
<label for='obb1'>Menu #3 </label>
<input type='text' name='obb3' value='' size='4'><br>
<input type='submit' value='objednat'></form>";
}
我想继续像这样
...} else {
echo " no match ";
}
非常感谢您的帮助。
答案 0 :(得分:4)
在这种情况下,您可以使用mysql_num_rows()
$resultt = mysql_query("SELECT * FROM objednavky WHERE kdo = '$kdo' and kdy = '$the_rday'");
if(mysql_num_rows($resultt)<1){
echo "not found";
}else{
while(...)
}
答案 1 :(得分:2)
这可以通过mysql_num_rows()
完成 if($resultt && mysql_num_rows($resultt)>1){
while ($roww = mysql_fetch_array($resultt)) {
echo "<form method='post' action=''>
<label for='obb1'>Menu #1 </label>
<input type='text' name='obb1' value='$roww[3]' size='4'><br>
<label for='obb1'>Menu #2 </label>
<input type='text' name='obb2' value='' size='4'><br>
<label for='obb1'>Menu #3 </label>
<input type='text' name='obb3' value='' size='4'><br>
<input type='submit' value='objednat'></form>";
}} else {
echo " no match ";
}
但不推荐使用mysql_*
函数,因此请改用pdo
或mysqli