2014-10-01 68 views
-3

如何讓PHP顯示一條消息,指出它找不到任何結果,而不是在查詢找不到任何結果時顯示任何結果結果如何?如何顯示找不到任何結果的錯誤消息

這裏是我的代碼結果的顯示

print " <table border = '1'> \n"; 



    print "  <tr> \n"; 

    while ($field = mysqli_fetch_field($result)){ 

    print "  <th>$field->name</th> \n"; 

    } // end while 

    print "  </tr> \n"; 



    while ($row = mysqli_fetch_assoc($result)){ 

    print "  <tr> \n"; 

    foreach ($row as $name => $value){ 

     print "  <td>$value</td> \n";  

    } // end foreach 



    print "  </tr> \n"; 



    } // end while loop 



    print " </table> \n"; 
+1

http://php.net/manual/en/mysqli-result.num-rows.php – CBroe 2014-10-01 13:42:38

回答

1

通過mysqli_num_rows(),你可以指望具有表中數據的行數。

$row_cnt = mysqli_num_rows($result); 

if($row_cnt > 0){ 
    //data exist for it 
}else{ 
    //Display your error message here 
} 
+0

謝謝你,很抱歉的壞研究我做到了。如果你願意,你可以關閉它。 – 2014-10-01 22:23:03

+0

+1(你接受你的錯誤.. :) – 2014-10-03 07:55:32

相關問題