Hi there,
I have this below code where it makes a keyword search.
It works fine but my problem is when results are shown I want to use the pagination feature. Like 10 results per page.
I am wondering how can I accomplish this task?
Many thanks in advance.
------------------------------------
<?php
require ('common.php');
PrintHead("Search Messages");
if($logged_in=='yes')
{
echo "
<center><h4>$_lang[searchmessages]</h4></center>
<center>
<form class=\"form\" method=\"post\" action=\"search.php\">
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td class=\"fieldtitle\">$lang[enterkeyword] </td>
<td><input class=\"textbox\" type=\"text\" name=\"keyword\" title=\"$lang[enterkeyword]\" size=\"20\" maxlength=\"20\"></td>
<td> <input class=\"databutton\" type=\"submit\" value=\"$_lang[search]\"></td>
</tr>
</table>
</form>
</center>";
if(isset($keyword))
{
$keyword = trim($keyword);
if(strlen($keyword)==1) $keyword = "";
if( $keyword != "" )
{
/*
$SQL = "
SELECT LEFT(msg,200) AS msg, id, prev, boardid, posted, subject, author
FROM bweb_messages
WHERE
subject LIKE '%$keyword%' ||
msg LIKE '%$keyword%' ||
author LIKE '%$keyword%'
ORDER BY posted
DESC LIMIT 500
";
*/
/*
$SQL = "
SELECT id, prev, boardid, posted, subject, msg, author
FROM bweb_messages
WHERE
subject LIKE '%$keyword%' ||
msg LIKE '%$keyword%' ||
author LIKE '%$keyword%'
ORDER BY posted
DESC LIMIT 50
";
*/
$SQL = "
SELECT id, subject, msg, author,
MATCH(msg, subject, author) AGAINST('$keyword') AS score
FROM bweb_messages
WHERE MATCH(msg, subject, author) AGAINST('$keyword')
ORDER BY score DESC
";
$result = mysql_query($SQL);
$foundNum = mysql_num_rows($result);
$keyword = stripslashes($keyword);
$keyword = str_replace("," , "", $keyword);
echo "
<center>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"80%\">
<tr>
<td width=\"100%\" height=\"20\" colspan=\"2\">$_lang[search_results]</td>
</tr>
<tr>
<td width=\"100%\" height=\"1\" bgcolor=\"#808080\" colspan=\"2\"></td>
</tr>";
$i = 1;
while( $row = mysql_fetch_array( $result ) )
{
//$score = $row['score'];
$id = "{$row[ 'id' ]}";
$row[ 'subject' ] = eregi_replace( $keyword, "<b><font color=red>$keyword</font></b>", $row[ 'subject' ] );
$row[ 'msg' ] = eregi_replace( $keyword, "<b><font color=red>$keyword</b></font>", $row[ 'msg' ] );
$row[ 'author' ] = eregi_replace( $keyword, "<b><font color=red>$keyword</b></font>", $row[ 'author' ] );
$short_msg = substr_replace($row['msg'], '...', 200);
$short_msg = htmlspecialchars($short_msg);
echo "
<tr>
<td width=\"3% \" height=\"20\"><b>$i.</b> <!-- $score --></td>
<td width=\"97%\" height=\"20\"><a href=$Config[http_base]/$Config[msg_script]/$id?highlight=$keyword>{$row[ 'subject' ]}</a> by {$row[ 'author' ]} <font color=#808080><small>- " .
strftime( "%c", $row[ 'posted' ] ) . "</small></font></td>
</tr>
<tr>
<td width=\"3%\" height=\"20\"></td>
<td width=\"97%\" height=\"20\">{$short_msg}</td>
</tr>";
$i++;
}
echo "
<tr>
<td width=100% height=1 bgcolor=#808080 colspan=2>
</tr>
</tr>
</table>
</center>";
}
}
mysql_free_result($result);
}
else {
echo $_lang[have2login];
}
PrintFoot();
?>