How to do pagination for search result.I included my code
Posted: Tue Aug 18, 2009 1:51 am
I did the pagination for the normal database result.. But i can't do it for the search result..I included the code here(In this code the first result page is displaying but the second page is not getting display..).. Plz any one help me to solve this problem....Advance Thanx...
Code: Select all
$yut=0;
$quer =mysql_query("select *from post_pre where admin_app = 'YES'");
while($sf = mysql_fetch_array($quer))
{
$str1 = $sf['job_tit'];
if(stristr($str1,$key_ser))
{
$yut++;
}
else
{
$str1 = $sf['job_cata'];
if(stristr($str1,$key_fun))
{
$yut++;
}
else
{
$str1 = $sf['job_loc_city'];
if(stristr($str1,$key_loc))
{
$yut++;
}
else
{
$str1 = $sf['exper_desc'];
if(stristr($str1,$key_exp))
{
$yut++;
}
else
{
$str1 = $sf['job_type'];
if(stristr($str1,$job_type))
{
$yut++;
}
}
}
}
}
}
if (isset($_REQUEST['pageno'])) {
$pageno = $_REQUEST['pageno'];
} else {
$pageno = 1;
}
$numrows=$yut;
$rows_per_page = 3;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if($pageno > $lastpage)
$pageno = $lastpage;
if ($pageno < 1 )
$pageno = 1;
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$quer =mysql_query("select *from post_pre where admin_app = 'YES' order by ID desc $limit");
while($sf = mysql_fetch_array($quer))
{
$str1 = $sf['job_tit'];
if(stristr($str1,$key_ser))
{
?>
<tr>
<td height="30" width="32%"><a href="?action=<?php echo $sf['ID']; ?> "><?php echo $sf['job_tit']; ?></a></td>
<td height="30" width="22%"><?php echo $sf['post_by']; ?></td>
<?php
}
else
{
$str1 = $sf['job_cata'];
if(stristr($str1,$key_fun))
{?>
<tr>
<td height="30" width="32%"><a href="?action=<?php echo $sf['ID']; ?> "><?php echo $sf['job_tit']; ?></a></td>
<td height="30" width="22%"><?php echo $sf['post_by']; ?></td>
<?php
}
else
{
$str1 = $sf['job_loc_city'];
if(stristr($str1,$key_loc))
{
?>
<tr>
<td height="30" width="32%"><a href="?action=<?php echo $sf['ID']; ?> "><?php echo $sf['job_tit']; ?></a></td>
<td height="30" width="22%"><?php echo $sf['post_by']; ?></td>
<?php
}
else
{
$str1 = $sf['exper_desc'];
if(stristr($str1,$key_exp))
{
?>
<tr>
<td height="30" width="32%"><a href="?action=<?php echo $sf['ID']; ?> "><?php echo $sf['job_tit']; ?></a></td>
<td height="30" width="22%"><?php echo $sf['post_by']; ?></td>
<?php
}
else
{
$str23 = $sf['job_type'];
if(stristr($str23,$job_type))
{
?>
<tr>
<td height="30" width="32%"><a href="?action=<?php echo $sf['ID']; ?> "><?php echo $sf['job_tit']; ?></a></td>
<td height="30" width="22%"><?php echo $sf['post_by']; ?></td>
<?php
}
}
}
}
}
}
if ($pageno == 1) {
} else {
echo "<td> <a href='?action=search&pageno=1&keywords=".$key_ser."&functionalarea=".$key_fun."&location=".$key_loc."&experience=".$key_exp."&jobtype=".$job_type." ' >FIRST</a></td> ";
$prevpage = $pageno-1;
echo "<td> <a href='?action=search&pageno=$prevpage&keywords=".$key_ser."&functionalarea=".$key_fun."&location=".$key_loc."&experience=".$key_exp."&jobtype=".$job_type." ' style='text-align:right;'>PREV</a> </td>";
}
//echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
} else {
$nextpage = $pageno+1;
echo "<td> <a href='?action=search&pageno=$nextpage&keywords=".$key_ser."&functionalarea=".$key_fun."&location=".$key_loc."&experience=".$key_exp."&jobtype=".$job_type." ' style='text-align:right;'>NEXT</a></td> ";
echo "<td> <a href='?action=search&pageno=$lastpage&keywords=".$key_ser."&functionalarea=".$key_fun."&location=".$key_loc."&experience=".$key_exp."&jobtype=".$job_type." ' style='text-align:right;'>LAST</a></td> ";
}