I am using the following code to excute a search query.The search giving me the exact result when i seach using only one field. If i use more than one field using if statement, it showing the exact page numbers like 1 2 next but when i clik on 2 it will show "no result found". I already spent lot of time to figure this out.
Any help would be appreciated
<?php
$page = $_REQUEST['page'];
$searchtype = $_REQUEST['searchtype'];
$search= $_REQUEST['search'];
if (!$page) {
$page = 1;
}
if($page > 1){
$search = $_REQUEST['search'];
$searchtype = $_REQUEST['searchtype'];
}
$limit = $page * 10;
$limit = $limit - 10;
?>
<table cellpadding=400 cellspacing=0 border=0><tr>
<td bgcolor=#FFFFFF width=400 height=18 valign=center align=left>
<font face="Times New Roman" size="3"><b>Search Results</b></font>
</td>
</tr>
<TR>
<TD valign=top>
<p><center>
<FONT face=Times New Roman size=3>Search results </font> </center>
</p>
<table cellspacing=0 cellpadding=2 border=0 width="400">
<?php
if ($searchtype == "D") {
$sql = "select distinct articleid from artlist where description like '%$search%'";
} elseif ($searchtype == "N") {
$sql = "select distinct articleid from article where title like '%$search%'";
} else {
$sql = "select distinct articleid from article where keywords like '%$search%'";
}
$result = mysql_query($sql ,$db);
$numrows = @mysql_numrows($result);
if($numrows < 10){
$through = $numrows;
} else {
$through = $limit + 10;
}
if ($through > $numrows){
$through = $total;
}
if($page > 1){
$from = $limit +1;
} else {
$from = $limit;
}
if($from == 0){
$from = $from +1;
}
$total_pages = ceil($numrows / 10);
if ($searchtype == "I") {
$sql = "select distinct articleid from artlist where description like '%$search%' LIMIT $limit,10";
} else if ($searchtype == "N") {
$sql = "select distinct articleid from article where title like '%$search%' LIMIT $limit,10";
} else{
$sql = "select distinct articleid from article where keywords like '%$search%' LIMIT $limit,10";
}
$result = mysql_query($sql ,$db);
$articlecount = 1;
if ($myrow = @mysql_fetch_array($result1)) {
do {
$articleid[$articlecount] = $myrow["articleid"];
$articlecount++;
} 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 article where articleid = $rarticleid[$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("<tr><td align=center>");
if ($page > 1) {
echo "<a href=$PHP_SELF?search=$search&page=".($page -1).">Previous</a> ";
}
if (($numrows > 10) && (($limit + 10) < $numrows)) {
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?search=$search&page=$i\">$i</a> ";
}
}
}
if (($numrows > 10) && (($limit + 10) < $numrows)) {
echo "<a href=$PHP_SELF?search=$search&page=".($page +1).">Next</a>";
}
printf("</td></tr>");
?>
</table>
</td>
</tr>
</table>
when i search using keword, it is working fine but not for description and title.
Please help me .
Thanks in advance.