首页 > 解决方案 > 根据结果​​隐藏一些分页

问题描述

我有分页,但它显示了所有结果。我想隐藏一些。

一直在尝试调整它,但没有好的结果。

$Num_Rows = mysqli_num_rows($objQuery);

$Per_Page = 10;   // Per Page

$Page = $_GET["Page"];
if (!$_GET["Page"]) {
    $Page = 1;
}

$Prev_Page = $Page - 1;
$Next_Page = $Page + 1;

$Page_Start = (($Per_Page * $Page) - $Per_Page);
if ($Num_Rows <= $Per_Page) {
    $Num_Pages = 1;
} else if (($Num_Rows % $Per_Page) == 0) {
    $Num_Pages = ($Num_Rows / $Per_Page);
} else {
    $Num_Pages = ($Num_Rows / $Per_Page) + 1;
    $Num_Pages = (int)$Num_Pages;
}


$strSQL .= " order  by lName ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysqli_query($db, $strSQL);

标签: phpmysqli

解决方案


试试下面的代码;

$query = "YOUR QUERY HERE";

$perPage = 10;
$page = isset($_GET["Page"]) ? $_GET["Page"] : 1;

$offset = ($page - 1) * $perPage;

$strSQL = $query." ORDER BY lName ASC LIMIT $offset , $perPage";
$objQuery = mysqli_query($db, $strSQL);

希望这可以帮助!


推荐阅读