将分页的地址后面加上,POST过去的参数,以get方式传送.
一般的分页函数后面都可以带个附加的参数的.

解决方案 »

  1.   

    将查詢條件存入cookie, 分页查询时再临时读取,怎么会出错?
      

  2.   

    $_POST刷新一次就没了啊,除非你把他存到隐藏域里,点下一次的时候再接受一次。
    不过最好还是用get方式接受参数
      

  3.   

     <?php
      $searchtype=$_GET['searchtype'];
      $searchterm=$_GET['searchterm'];
      $searchterm=trim($searchterm);
      //global $key;
      //$page=isset($_GET['page'])?intval($_GET['page']):1;
      $pageRecord=5;
      //setcookie("serachtype",$searchtype);
     // setcookie("searchterm",$searchterm);
      /*if(!$searchtype||!$searchterm)
      { echo '<p align="center">You have not enter search detail. please go back and try again </p>';
       exit;
      }*/      if(!get_magic_quotes_gpc()){
       $searchtype=addslashes($searchtype);
         $searchterm=stripslashes($searchterm);
              }     $db=new mysqli('localhost','root','root','book');   if(mysqli_connect_errno())
      { echo 'Error: Could not connectd to database .please check the database connection!';
        exit;
     }

    /*$pagenum=ceil($num_result/$num);//計算頁數
    //$offset=($page-1)*$pageRecord;
    if($page>$pagenum||$pagenum=0)
    {
    echo'Error:The page not Found!';
      exit;
    }*/
    //$key=array('type'=>$_GET['searchtype'],'term'=>$_GET['searchterm']);
      
    //$query="select * from books where ".$key['type']." like '%".$key['term']."%' ";
    $query="select * from books where ".$searchtype." like '%".$searchterm."%' ";
    echo $query;
    $result=mysqli_query($db,$query);
                    $num_results=mysqli_num_rows($result);
    require('Pager.php');
    $page_size=2;
    //总条目数
       $nums=$num_results;
    //每次显示的页数
       $sub_pages=10;

    if ($num_results !=0){
    echo '<br/><p> Number of book Fonud : '.$num_results.'</p>';
    echo '<table border="1" bgcolor="#cccccc">';
    echo '<tr><td><strong>Title </strong> </td>';
    echo '<td><strong>Author <strong></td>';
    echo '<td><strong> ISBN </strong></td>';
    echo '<td><strong> Price </strong></td></tr>'; for($i=0;$i <$page_size;$i++){
    $row=$result->fetch_assoc();
    /*echo '<tr><td> <p><strong>'.($i+1).'.Title :' ;
    echo '</strong></td><td>   Author:</td>' ;
    echo '<td>ISBN:</td>' ;
    echo '<td> Price:</td><tr>' ;*/
    echo '<tr><td>';
    echo htmlspecialchars(stripslashes($row['Title']));
    echo '</td><td>';
    echo stripslashes($row['Author']);
    echo '</td><td>';
    echo stripslashes($row['ISBN']);
    echo '</td><td>';
    echo stripslashes($row['price']);
    echo '</td><td></tr>';
     }
     echo ' <table><br/>';}
     else
        //echo' Book Not Found!';
    echo "<script> alter('Book Not Found') </script>";
            echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> '; 
    //echo <div align="center"> 
    /*for($i=1;$i<=$pagenum;$i++){
          $show=($i!=$page)?"<a href='result.php?page=".$i."'>[".$i."]</a>":"<b>[".$i."]</b>";
          echo $show." ";
       }
             echo $num_results.'条记录,每页5条,共'.$pagenum.'页';*/
       $pageCurrent=$_GET["p"];
       //if(!$pageCurrent) $pageCurrent=1;
     
       $subPages=new SubPages($page_size,$num_results,$pageCurrent,$sub_pages,"result.php?p=",1); $result->free();
    $db->close();
            
    ?> 这是我测试的例子,每次点下一页时,echo $query 都是显示"select * from books where like '%%' "说明 $searchtype,$searchterm
          的值被刷新变没了??