php - 根据结果隐藏一些分页
问题描述
我有分页,但它显示了所有结果。我想隐藏一些。
一直在尝试调整它,但没有好的结果。
$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);
解决方案
试试下面的代码;
$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);
希望这可以帮助!
推荐阅读
- c# - 使用 EPPlus 库识别并突出显示 Excel 工作表中的重复记录
- css - 防止字体呈现为表情符号
- java - 从测试文件填充 DefaultTableModel
- reactjs - React Material UI:在输入以外的其他东西上浮动标签
- java - Android Retrofit - 将响应放入 arraylist
- sql - 选择中的引用是什么意思?
- neo4j - Neo4j: return error if no matching nodes found when creating a relationship?
- python - 当只有一个组时,Groupby 应用会进行不需要的转置
- java - 如何在 Android 中同步 ExoPlayer 库?
- android - 如何将cardview动态添加到网格布局