我正在用 php 制作搜索引擎,但我没有收到或收到 0 个结果。当我搜索数据库中的关键字时,它没有显示任何结果。任何人都可以帮我解决我做错的地方。下面是我的代码。
<?php
$k = $_GET['k'];
$terms = explode(" ", $k);
$query = ("SELECT * FROM search WHERE ");
foreach($terms as $each){
$i++;
if($i == 1)
$query.= (" 'keywords' LIKE '%$each%' ");
else
$query.= (" OR 'keywords' LIKE '%$each%' ");
}
//Connect to db
require("./db.php");
$query = mysql_query($query);
$numrows = mysql_num_rows($query);
if( $numrows>0 ){
while( $row = mysql_fetch_assoc($query) )
$id = $row['id'];
$title = $row['title'];
$description = $row['description'];
$keywords = $row['keywords'];
$link = $row['link'];
echo "<h2><a href = '$link'>$title</a></h2> $description </br> </br>";
}
else
echo "No results were found for \"<b>$k</b>\"";
//Disconnect to db
mysql_close();
?>