如何使用PHP和MySQL在搜索中显示“无结果”?

如何使用PHP和MySQL在搜索中显示“无结果”?,php,mysql,search,Php,Mysql,Search,我想当用户运行搜索时,它会搜索我的数据库。如果它找到它,它会按照我想要的方式输出表。如果没有结果,它只返回一个空白页。我将如何制作它,以便如果没有找到结果,它会显示类似“对不起,没有结果”的内容。或者别的什么。我试过在while循环中使用一个计数器,比如$count=0和doing$count=$count+1,然后在while之后,doing if$count=0{echo No results.};但这只是在while循环中返回了一个错误 $result = mysqli_query($co

我想当用户运行搜索时,它会搜索我的数据库。如果它找到它,它会按照我想要的方式输出表。如果没有结果,它只返回一个空白页。我将如何制作它,以便如果没有找到结果,它会显示类似“对不起,没有结果”的内容。或者别的什么。我试过在while循环中使用一个计数器,比如$count=0和doing$count=$count+1,然后在while之后,doing if$count=0{echo No results.};但这只是在while循环中返回了一个错误

$result = mysqli_query($con,"SELECT * FROM equipmentt WHERE title like '%$search%' or description like '%$search%' or incondition like '%$search%' or assetnumber like '%$search%' or manufacturer like '%$search%' or model like '%$search%' or yearof like '%$search%' or serialnumber like '%$search%' or dimensions like '%$search%' or speed like '%$search%' or electricity like '%$search%' or shippingweight like '%$search%' or status like '%$search%'");


while($row = mysqli_fetch_array($result))
{
 echo "<table cellpadding='0' cellspacing='0' id='equiptable'>
<tr><td>
<table><tr><td id='eqimg'><img src='" . $row['img'] . "'></td><td>
<table id='altrow' cellpadding='0' cellspacing='0'>
<tr><td colspan='2' id='eqtitle'>" . $row['title'] . "</td></tr>
<tr><td class='b'>Description</td><td>" . $row['description'] . "</td></tr>
<tr><td class='b'>Condition</td><td>" . $row['incondition'] . "</td></tr>
<tr><td class='b'>Asset Number</td><td>" . $row['assetnumber'] . "</td></tr>
<tr><td class='b'>Manufacturer</td><td>" . $row['manufacturer'] . "</td></tr>
<tr><td class='b'>Model</td><td>" . $row['model'] . "</td></tr>
<tr><td class='b'>Status</td><td class='" . $row['status'] . "'>" . $row['status'] . "</td></tr>
<tr><td class='b'>Year</td><td>" . $row['yearof'] . "</td></tr>
<tr><td class='b'>Serial Number</td><td>" . $row['serialnumber'] . "</td></tr>
<tr><td class='b'>Dimensions</td><td>" . $row['dimensions'] . "</td></tr>
<tr><td class='b'>Speed</td><td>" . $row['speed'] . "</td></tr>
<tr><td class='b'>Electricity</td><td>" . $row['electricity'] . "</td></tr>
<tr><td class='b'>Shipping Weight</td><td>" . $row['shippingweight'] . "</td></tr>
</table>
</td></tr>
</table>
<p>";
}

mysqli_close($con);

您可能会遇到错误,因为您使用的是mysqli\u fetch\u数组而不是mysqli\u fetch\u assoc, 否则,柜台不是个坏主意

您还可以使用获取总计数


编辑:如果要使用用户输入进行db操作,还应该考虑使用。

我使用了num_行并将其设置为count。然后在$count==0时使用{echo No results.}非常感谢!此外,我目前正在调查mysqli_fetch_assoc,因此感谢您的建议!