【发布时间】:2013-12-25 09:38:14
【问题描述】:
只是想知道当我在搜索栏中输入内容时如何显示此消息,但没有任何内容与存储在我的 MySQL 数据库中的内容匹配。
到目前为止,我拥有的是这个。
<?php
if(isset($_POST['submit'])){
$search = trim($_POST['search']);
if($search != ""){
//echo "search: ". $search;
$result = mysql_query("SELECT * FROM catalogue WHERE
name LIKE '$name' OR
category LIKE '$category' OR
brand LIKE '$brand' OR
season LIKE '$season' OR
price LIKE '$price' OR
store LIKE '$store' OR
description LIKE '%$search%' ");
while($row = mysql_fetch_array($result)){
$name = $row['name'];
$file = $row['file'];
$description = $row['description'];
$category = $row['category'];
$brand = $row['brand'];
$season = $row['season'];
$price = $row['price'];
$store = $row['store'];
$cid = $row['cid'];
echo "\n<div class=\"thumb\">";
echo "\n\t<a href=\"single.php?cid=$cid\"><img src=\"thumbs/$file\" class=\"thumbnailImg\" width=\"150\" height=\"200\"/></a><br/>";
echo "\n\t".$name. " ";
echo "\n\t$". $price;
echo "\n</div>";
}//end while loop
}else{
echo "<h2><em>No results were found.</em></h2>";
}//end if search ,else
}//end if submit
?>
如果我只单击搜索而不输入任何内容,则此代码 sn-p 有效,但如果我在搜索中输入不匹配的内容,则不会显示任何内容。我该如何解决?
【问题讨论】:
-
if ( mysql_num_rows($result) == 0 ){ echo "No results found!"; die(); }