想知道如何在我的搜索欄中輸入內容時顯示此消息,並且沒有任何內容與我的MySQL數據庫中存儲的內容相匹配。如何顯示「未找到結果」消息(PHP)
到目前爲止我所擁有的就是這個。
<?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
?>
這段代碼工作,如果我只需點擊搜索,而無需輸入任何東西,但如果我在不匹配搜索輸入的東西,什麼也不顯示。我如何解決這個問題?
'if(mysql_num_rows($ result)== 0){echo「No results found!」;死(); }' – Hussain