こんにちは、シンプルな検索エンジンを作成しましたが、1 つの問題があります。文字列を検索すると、結果が 1 行しか表示されません。
Search.php:
<?php
if (isset($_POST['search']) && !empty($_POST['xs']) && isset($_POST['s']))
echo $functions->Search($_POST['xs'], $_POST['s']);
?>
functions.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>
';
}
}
問題 1 つの結果のみが複数必要です。