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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mayilarun
Forum Newbie
Posts: 3
Joined: Tue Aug 18, 2009 1:38 am

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

Post 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> ";
}
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

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

Post by jackpf »

Wow...your code is horribly (not) indented...and you haven't used code tags...

Have you googled a pagination tutorial?
mayilarun
Forum Newbie
Posts: 3
Joined: Tue Aug 18, 2009 1:38 am

How to do pagination for search result?

Post 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..
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How to do pagination for search result?

Post 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
(#10850)
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: How to do pagination for search result?

Post by jackpf »

Guess you weren't happy with your first thread: viewtopic.php?f=1&t=104885&p=560641
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post by Christopher »

Well spotted jackpf!

Merged topics.
(#10850)
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

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

Post by jackpf »

He's got another one lol
viewtopic.php?f=1&t=105009
Post Reply