0

我有这段代码,它将mysql结果分成每页10个结果。但我想对其进行编辑,以便根据当前页面限制链接。所以在第 1-10 页上它只显示页面链接 1-10 在第 11-20 页上它只显示页面链接 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;
}
4

1 回答 1

0

做这个

"SELECT * FROM document WHERE email='$_SESSION[email]' ORDER BY id DESC LIMIT 10 OFFSET $start_from";

告诉我它是否有效。

于 2013-02-11T21:22:10.260 回答