Hi,
I am working on a seach script, it showing me some problem on pagination.After the search it showing nextpage but when i click it it showing no results. I couldnot figure it out. Can any one help me to solve this issue..?
This is the code which i am using for searching.
Search.php
<form action=results20.php method=post>
<table width="259" cellspacing="0" cellpadding="3" align="center" bgcolor="#FFFFFF" style="border: 1px solid #ffffff;">
<tr bgcolor="#FFFFFF"><td width="251" height="27" align="left">
<font size=2 face='Arial'><strong>Search by</strong></font></td>
</tr>
<tr bgcolor="#FFFFFF"><td height="100">
<p><font size="3" face="Times New Roman"><input type=radio name=search value="K">
<strong>Keyword</strong></font></p>
<p><font size="3" face="Times New Roman"><input type=radio name=search value="T">
<strong>Article Name</strong> </font></p>
<p><font size="3" face="Times New Roman"><input type=radio name=search value="D">
<strong>Description</strong> </font> </p></td>
</tr>
<tr bgcolor="#FFFFFF" height="27"><td align="right">
<input type=text name=search size=25> <input type=submit value=Search>
</td>
</tr></table>
</form>
result.php
<?php
$pagenum = 0;
$searchtype = $_REQUEST['searchtype'];
$search = $_REQUEST['search'];
if ($_REQUEST['pagenum'])
{
$pagenum = $_REQUEST['pagenum'];
}
<table width="630" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="650" valign="top">
<TABLE width=600 cellpadding=5 cellspacing=0 border=0>
<tr><td width=500 align=center>
<table cellpadding=1 cellspacing=1 border=0><tr><td bgcolor=#FFFFFF width=500 height=20 valign=center align=center>
<table cellpadding=0 cellspacing=0 border=0><tr>
<td bgcolor=#FFFFFF width=498 height=18 valign=center align=left>
<font face="Times New Roman" size="3"><b>Search Results</b></font>
</td>
</tr>
</table>
</td></tr></table>
</td></tr>
<TR>
<TD valign=top>
Here are all the Articles containing the <?php printf($search); ?>
<table cellspacing=0 cellpadding=2 border=0 width="400">
<?php
if ($searchtype == 'K') {
$sql = "select distinct articleid from articles where keywords like '%$search%'";
} else if ($searchtype == 'D') {
$sql = "select articleid from articles where description like '%$search%'";
} else {
$sql = "select articleid from articles where title like '%$search%'";
}
$result = mysql_query($sql ,$db);
$numrows = @mysql_numrows($result);
$lastpage = false;
if ($pagenum == 0) {
$startrow = 0;
} else {
$startrow = 25 * $pagenum;
}
if ($numrows < $startrow + 25) {
$endrow = $numrows;
$lastpage = true;
}
if ($searchtype == 'K') {
$sql = "select distinct articleid from articles where keywords like '%$search%' limit $startrow,25";
} else if ($searchtype == 'D') {
$sql = "select articleid from articles where description like '%$search%' limit $startrow,25";
} else {
$sql = "select articleid from articles where title like '%$search%' limit $startrow,25";
}
$result = mysql_query($sql ,$db);
$acount = 1;
if ($myrow = @mysql_fetch_array($result)) {
do {
$articleid[$acount] = $myrow["articleid"];
$acount++;
} while ($myrow = mysql_fetch_array($result));
}
if (count($articleid) == 0) {
printf("<tr><td colspan=3><p><center><FONT face=Times New Roman size=3><b>No Results Found</b></font></center></p></td></tr>");
} else {
for ($k = 1; $k <= count($articleid); $k++) {
$sql = "select articleid, title, date, rating, status from articles where articleid = $articleid[$k]";
$result = mysql_query($sql ,$db);
if ($myrow = mysql_fetch_array($result)) {
do {
if ($myrow["status"] == "L") {
printf("<tr><td>");
printf("<FONT face=Times New Roman, Times, serif size=3><a href=article.php?articleid=%s>%s</a> </font>", $myrow["articleid"], $myrow["title"]);
printf("</td>");
printf("</tr>");
}
} while ($myrow = mysql_fetch_array($result));
}
}
}
printf($numrows);
printf("<tr><td align=center>");
if ($startrow > 0) {
printf("<FONT size=3><a href=results.php?pagenum=%s&search=%s>Previous Page |</a></font>",$pagenum-1, $search);
} else {
printf("");
}
if ($lastpage == false) {
printf("<FONT size=3><a href=results.php?pagenum=%s&search=%s>Next Page</a></font>", $pagenum+1, $search);
} else {
printf("");
}
printf("</td></tr>");
?>
</table>
</TD>
</TR>
</TABLE>
</td>
</tr>
</table>