我正在使用PHP搜索我的数据库,并在单独的搜索结果页面上显示信息。请参阅下面的PHP脚本。使用我当前的脚本,我只能展示一个结果。如何展示多个结果?另外,如何在PHP代码的一部分中添加CSS类?
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$k = $_GET['k'];
$terms = explode(" ", $k);
$query = "SELECT * FROM search WHERE ";
$i = 0;
foreach ($terms as $each){
$i++;
if ($i == 1)
{
$query .= "keywords LIKE '$each%' ";
}
else
{
$query .= "OR keywords LIKE '$each%' ";
}
}
// connect
mysql_connect("host","user","pass");
mysql_select_db("DB1");
$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 "<h1><a href='$link'>$title</a></h1>
<h2>$link</h2><br /><br />
$description<br /><br />
$keywords<br /><br />";
}
}
else
{
echo "No Search Results Were Found for \"<b>$k<b>\"";
}
// disconnect
mysql_close();
?>
请帮忙!提前谢谢。