限制基于当前页面的页面链接

时间:2013-02-11 21:08:59

标签: php html

我有这个代码,它将mysql结果分成每页10个结果。但我想编辑它,以便根据当前页面限制链接。因此,在第1-10页上,它仅显示第11-20页的页面链接1-10,它仅显示页面链接11-20,依此类推。我怎么能实现这个目标?谢谢。

if (isset($_GET["page"])) 
  { 
    $page  = $_GET["page"];
  } 
    else 
  { 
    $page=1; 
  };

$start_from = ($page-1) * 10;
$message =  "SELECT * FROM document WHERE email='$_SESSION[email]' ORDER BY id DESC LIMIT $start_from , 10";

              // echo  results

             // make page links for results

  $sql = "SELECT id FROM document WHERE email = '$_SESSION[email]'";
  $rs_result = $db->query($sql);
  $total_records = $rs_result->num_rows;
  $total_pages = ceil($total_records / 10);

if($rs_result->num_rows >10) {

    $page = "<p class = 'page'>";
for ($i=1; $i<=$total_pages; $i++) 
  {
    $page .="<a href='results.html?page=".$i."'>".$i."</a> ";
  }
    $page .="</p>";
    echo $page;
}

1 个答案:

答案 0 :(得分:0)

这样做

“SELECT * FROM document WHERE email ='$ _ SESSION [email]'ORDER BY id DESC LIMIT 10 OFFSET $ start_from”;

告诉我它是否有效。