大家好,我做了一个简单的搜索引擎,但是它有一个问题,当我搜索一个字符串时,我的结果只有一行我做错了什么我找不到多个结果。
搜索.php:
<?php
if (isset($_POST['search']) && !empty($_POST['xs']) && isset($_POST['s']))
echo $functions->Search($_POST['xs'], $_POST['s']);
?>
函数.php:
function Search( $post, $type )
{
global $database;
if ($database->getSearchData($type, $post) && preg_replace("/[^0-9A-Za-z]/", "", $post))
return $database->getSearchData($type, $post);
else
return
'
<div class="title_box"><div class="title_inner">
Results </div></div>
<div class="title2_box"><div class="title2_inner">
<p>
<table width="50%">
<tr>
<td>Player</td>
<td>Level</td>
<td>Total honour</td>
</tr>
<tr><td class="f" colspan="2">No results</td></tr></table> </p>
</div></div>
';
}
数据库.php:
function getSearchData($type, $keyword)
{
$find = strtoupper( $find );
$find = strip_tags( $find );
$find = trim ( $find );
switch($type)
{
case '1':
$q = "SELECT * FROM users WHERE upper(username) LIKE '%$keyword%'";
break;
case '2':
//$q = "SELECT * FROM guilds WHERE upper(username) LIKE '%$keyword%' LIMIT 25";
return false;
break;
case '3':
//$q = "SELECT * FROM guilds WHERE upper(username) LIKE '%$keyword%' LIMIT 25";
return false;
break;
default:
return false;
break;
}
$result = mysql_query($q, $this->connection);
if(mysql_num_rows($result) <= 0)
return false;
while($row = mysql_fetch_array( $result ))
{
return
'
<div class="title_box"><div class="title_inner">
Results </div></div>
<div class="title2_box"><div class="title2_inner">
<p>
<table width="50%">
<tr>
<td>Player</td>
<td>Level</td>
<td>Total honour</td>
</tr>
<tr>
<td>
<a href="index.php?mod=player&p='.$row['id'].'" " target="_self">'.$row['username'].'</a>
</td>
<td style="text-align:center">'.$row['level'].'</td>
<td style="text-align:center">'.$row['honour'].'</td>
</tr>
</table> </p>
</div></div>
';
}
}
问题只有一个结果需要多个。