Click here to Skip to main content
15,174,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am facing one problem of pagination.
Actually I did pagination successfully,but problem is getting by where clause
I used SELECT query with WHERE clause.Using input field.
Now the problem is that "while choosing the page of that pagination I have to again choose that input fields which used in the where clause.
Here is my piece of code :
PHP
<?php
   $i = 0;

                if(!empty($_POST['select2']))
                {
        foreach ($_POST['select2'] as $selectedOption)
            {
                $options[$i++] = $selectedOption;
            }
                }

if (isset($_GET['pageno'])) {
   $pageno = $_GET['pageno'];
} else {
   $pageno = 1;
}
      $sql ="select DISTINCT date,mobno,city,state,type,telecaller,time FROM import";
    $query  = mysql_query($sql);
      $query_data = mysql_num_rows($query);

$numrows = $query_data;
$rows_per_page = 10;
$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;
            $sql = "select date,mobno,city,state,type,telecaller FROM import WHERE time IN(";
        $num = count($options);
        for ($i=0; $i<$num-1; $i++)
        {
        $sql .= "'".$options[$i]."', ";
        }
        $sql .= "'".$options[$i]."')";
        $sql .= "GROUP BY mobno,telecaller ORDER BY date DESC $limit";
       // OR date1='$_POST[date]'
        //echo $sql . "<br>";
          $query  = mysql_query($sql);
            echo"<div id='pagination'>";
if ($pageno == 1) {
   echo " FIRST    PREV &nbsp &nbsp &nbsp ";
} else {
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> &nbsp &nbsp &nbsp ";
   $prevpage = $pageno-1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> &nbsp &nbsp &nbsp ";
}
echo"</div>";
echo"<div id='pagination1'>";
echo " ( Page <b>$pageno</b> of $lastpage ) &nbsp &nbsp &nbsp";
echo"</div>";
echo"<div id='pagination2'>";
if ($pageno == $lastpage) {
   echo " NEXT   LAST &nbsp &nbsp &nbsp";
} else {
   $nextpage = $pageno+1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> &nbsp &nbsp &nbsp";
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
}
echo"</div>";
Posted

1 solution

You might want to consider using sessions[^] to store the needed inputs for your SQL WHERE clause. You could also have them in a hidden field (HTML form) or build them into the pagination links of course.

Regards,

— Manfred
   
Comments
project virus 12-Sep-12 7:45am
   
Actually I got your point but i really don't know how to do it?so can you please tell me with my pagination coding??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900