I have a simple pagination script for my search, but I'm facing some trouble.
When I change the page, the query returns to the initial definition. Something like:
Definition: Select * from a;
Search: Select * from a where a.id = 1;
And then when I go to the 2nd page the query becames that: Select * from a; again.
The code: I have a form with some fields for the search and then the script:
 $sqlCount_pre = "SELECT COUNT('*') FROM a ";
 $sqlCount_pre .= " INNER JOIN b ON a.id = b.id ";
 if( sizeof( $where ) ){
    $sqlCount_pre .= ' WHERE '.implode( ' AND ',$where );
 }
 $max = 2;
 $sqlCount = mysql_query($sqlCount_pre);
 $sqlResult = ceil(mysql_result($sqlCount, 0) / $max);
 $pg = (isset($_GET["pg"])) ? (int)$_GET["pg"] : 1 ;
 $start = ($pg - 1) * $max;
 $sqlQuery = "SELECT a.* FROM a ";
 $sqlQuery .= " INNER JOIN b ON a.id = b.id ";
 if( sizeof( $where ) ){
    $sqlQuery .= ' WHERE '.implode( ' AND ',$where );
    $sqlQuery .= " LIMIT $start, $max";
 }else{
    $sqlQuery .= " LIMIT $start, $max";
 }
$sql = mysql_query($sqlQuery) or die(mysql_error());
Then i show the result in the page. After that i put the page links, as in this code:
<?php
   if($sqlResult > 1 && $pg<= $sqlResult){
       for($i=1; $i<=$sqlResult; $i++){
           echo "<a href='?pg=$i'>$i</a> ";
       }
   }       
?>
Is there something wrong or missing in this code?
 
     
     
     
    