php mysqli搜索如果找到,则显示,否则表示未找到
简单的方法是php mysqli搜索如果找到,则显示,否则表示未找到,php,mysql,mysqli,Php,Mysql,Mysqli,简单的方法是 <form method="post" action="search.php" id="Search"> <input type="text" name="name"> <input type="submit" name="submit" value="Search"> </form> if(mysqli\u num\u rows($result)>0)//如果有多个条目 { while($row=mysqli\u fetch\u数
<form method="post" action="search.php" id="Search">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
if(mysqli\u num\u rows($result)>0)//如果有多个条目
{
while($row=mysqli\u fetch\u数组($result))
{
echo$row['year']。.$row['model']。$row['color']。$row['license_-plate']。$row['vin']。$row['redward'];
回声“
”;
}
}
else//使用else语句比使用第二个if语句更好
{
echo“在我们的数据库中找不到汽车”;
}
mysqli_close($con);
编辑
如Fred评论中所述,将您的表格更改为:
if (mysqli_num_rows($result) > 0) // if there is more than 0 entry
{
while ($row = mysqli_fetch_array($result))
{
echo $row['year'] . " " . $row['model'] . " " . $row['color'] . " " . $row['license_plate'] . " " . $row['vin'] . " " . $row['reward'];
echo "<br>";
}
}
else // using an else statement is better than the second if
{
echo "car was not found in our database";
}
mysqli_close($con);
Parse error:syntax error,在第23行的D:\EasyPHP\data\localweb\search.php中出现意外的'else'(T_else)(见下一个问题…)@弗雷德二世称之为“共同努力”+我是弗雷德!!!!!!!!!!!!!!!!还有迈克尔@不客气。$name=$\u POST['Search']代码>显示HTML表单的外观。这充其量只是猜测。另外,确保您的数据库和表确实命名为cars
。SQL通常不是这样工作的。是的,DB被命名为“cars”,表也被命名为“cars”,不知道它是否重要,问题是否已解决。不客气。天哪!!!你搞定了,哈哈!
if (mysqli_num_rows($result) > 0) // if there is more than 0 entry
{
while ($row = mysqli_fetch_array($result))
{
echo $row['year'] . " " . $row['model'] . " " . $row['color'] . " " . $row['license_plate'] . " " . $row['vin'] . " " . $row['reward'];
echo "<br>";
}
}
else // using an else statement is better than the second if
{
echo "car was not found in our database";
}
mysqli_close($con);
<form method="post" action="search.php" id="Search">
<input type="text" name="Search"/>
<input type="submit" name="submit"/>
</form>