0

我怎样才能写一个条件,如果没有找到该行然后做某事?

我的代码

$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&emsp;</label>
                                  <input type='text' name='obb1' value='$roww[3]' size='4'><br>
                                  <label for='obb1'>Menu #2&emsp;</label>
                                  <input type='text' name='obb2' value='' size='4'><br>
                                  <label for='obb1'>Menu #3&emsp;</label>
                                  <input type='text' name='obb3' value='' size='4'><br>
                                  <input type='submit' value='objednat'></form>";


                        }

我想继续这样

   ...} else {
echo " no match ";
}

非常感谢您的帮助。

4

2 回答 2

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(...)

       }
于 2012-10-18T17:38:23.680 回答
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&emsp;</label>
                              <input type='text' name='obb1' value='$roww[3]' size='4'><br>
                              <label for='obb1'>Menu #2&emsp;</label>
                              <input type='text' name='obb2' value='' size='4'><br>
                              <label for='obb1'>Menu #3&emsp;</label>
                              <input type='text' name='obb3' value='' size='4'><br>
                              <input type='submit' value='objednat'></form>";


                    }}  else {
                         echo " no match ";
                       }

但是mysql_*不推荐使用函数,所以使用pdoormysqli代替

于 2012-10-18T17:38:00.777 回答