Displaying message when no results found in PHP MySQL search

前端 未结 8 1946
独厮守ぢ
独厮守ぢ 2020-12-11 07:07

I have a PHP search script which queries a MySQL database. Currently, when no results are displayed the script shows and error. How can I make it display a message like \"No

8条回答
  •  一向
    一向 (楼主)
    2020-12-11 07:33

    How about a simple counter in the while statement:

    $i = 0;
    
    while (condition) {
       $i++;
       do stuff;
    }
    
    if ($i ==0) {echo 'No results found';}
    

提交回复
热议问题