Page 1 of 1

How to do pagination for search result.I included my code

Posted: Tue Aug 18, 2009 1:51 am
by mayilarun
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> ";
}

Re: How to do pagination for search result.I included my code

Posted: Tue Aug 18, 2009 6:06 am
by jackpf
Wow...your code is horribly (not) indented...and you haven't used code tags...

Have you googled a pagination tutorial?

How to do pagination for search result?

Posted: Wed Aug 19, 2009 12:26 am
by mayilarun
If any one knows .. How to do pagination for searched results please give me the link or send the code.. or refer any tutorials.. It's very helpful for my project..Advance Thanx..

Re: How to do pagination for search result?

Posted: Wed Aug 19, 2009 3:08 am
by Christopher
Here are some thread I found by searching for "pagination" that may help:

viewtopic.php?f=1&t=99682
viewtopic.php?f=1&t=101344
viewtopic.php?f=50&t=100934

Re: How to do pagination for search result?

Posted: Wed Aug 19, 2009 8:44 am
by jackpf
Guess you weren't happy with your first thread: viewtopic.php?f=1&t=104885&p=560641

Re: How to do pagination for search result.I included my code

Posted: Wed Aug 19, 2009 1:38 pm
by Christopher
Well spotted jackpf!

Merged topics.

Re: How to do pagination for search result.I included my code

Posted: Thu Aug 20, 2009 7:49 am
by jackpf
He's got another one lol
viewtopic.php?f=1&t=105009