容易,方便,功能全的php分页类
简单,方便,功能全的php分页类
<br>
分页类代码<br>
<?php
class
SubPages{
private
$each_disNums
;
//每页显示的条目数
private
$nums
;
//总条目数
private
$current_page
;
//当前被选中的页
private
$sub_pages
;
//每次显示的页数
private
$pageNums
;
//总页数
private
$page_array
=
array
();
//用来构造分页的数组
private
$subPage_link
;
//每个分页的链接
private
$subPage_type
;
//显示分页的类型
/*
__construct是SubPages的构造函数,用来在创建类的时候自动运行.
@$each_disNums 每页显示的条目数
@nums 总条目数
@current_num 当前被选中的页
@sub_pages 每次显示的页数
@subPage_link 每个分页的链接
@subPage_type 显示分页的类型
当@subPage_type=1的时候为普通分页模式
example: 共4523条记录,每页显示10条,当前第1/453页 [首页] [上页] [下页] [尾页]
当@subPage_type=2的时候为经典分页样式
example: 当前第1/453页 [首页] [上页] 1 2 3 4 5 6 7 8 9 10 [下页] [尾页]
*/
function
__construct(
$each_disNums
,
$nums
,
$current_page
,
$sub_pages
,
$subPage_link
,
$subPage_type
){
<code class="php variable">$this->each_disNums=
intval
(
$each_disNums
);
<code class="php variable">$this->nums=
intval
(
$nums
);
if
(!
$current_page
){
<code class="php variable">$this->current_page=1;
}
else
{
<code class="php variable">$this->current_page=
intval
(
$current_page
);
}
<code class="php variable">$this->sub_pages=
intval
(
$sub_pages
);
<code class="php variable">$this->pageNums=
ceil
(
$nums
/
$each_disNums
);
<code class="php variable">$this->subPage_link=
$subPage_link
;
<code class="php variable">$this->show_SubPages(
$subPage_type
);
//echo $this->pageNums."--".$this->sub_pages;
}
/*
__destruct析构函数,当类不在使用的时候调用,该函数用来释放资源。
*/
function
__destruct(){
unset(
$each_disNums
);
unset(
$nums
);
unset(
$current_page
);
unset(
$sub_pages
);
unset(
$pageNums
);
unset(
$page_array
);
unset(
$subPage_link
);
unset(
$subPage_type
);
}
/*
show_SubPages函数用在构造函数里面。而且用来判断显示什么样子的分页
*/
function
show_SubPages(
$subPage_type
){
if
(
$subPage_type
== 1){
<code class="php variable">$this->subPageCss1();
}
elseif
(
$subPage_type
== 2){
<code class="php variable">$this->subPageCss2();
}
}
/*
用来给建立分页的数组初始化的函数。
*/
function
initArray(){
for
(
$i
=0;
$i
<code class="php variable">$this
->sub_pages;
$i
++){
<code class="php variable">$this->page_array[
$i
]=
$i
;
}
return
<code class="php variable">$this->page_array;
}
/*
construct_num_Page该函数使用来构造显示的条目
即使:[1][2][3][4][5][6][7][8][9][10]
*/
function
construct_num_Page(){
if
(
<code class="php variable">$this->pageNums <code class="php variable">$this
->sub_pages){
$current_array
=
array
();
for
(
$i
=0;
$i
<code class="php variable">$this
->pageNums;
$i
++){
$current_array
[
$i
]=
$i
+1;
}
}
else
{
$current_array
=
<code class="php variable">$this->initArray();
if
(
<code class="php variable">$this->current_page
<div class="line number92 index91 alt1">
<code class="php spaces">
for
(
$i
=0;
$i
<code class="php functions">count
(
$current_array
);
$i
++){
$current_array
[
$i
]=
$i
+1;
}
}
elseif
(
<code class="php variable">$this->current_page <code class="php variable">$this
->pageNums &&
<code class="php variable">$this->current_page >
<code class="php variable">$this->pageNums -
<code class="php variable">$this->sub_pages + 1 ){
for
(
$i
=0;
$i
<code class="php functions">count
(
$current_array
);
$i
++){
$current_array
[
$i
]=(
<code class="php variable">$this->pageNums)-(
<code class="php variable">$this->sub_pages)+1+
$i
;
}
}
else
{
for
(
$i
=0;
$i
<code class="php functions">count
(
$current_array
);
$i
++){
$current_array
[
$i
]=
<code class="php variable">$this->current_page-2+
$i
;
}
}
}
return
$current_array
;
}
/*
构造普通模式的分页
共4523条记录,每页显示10条,当前第1/453页 [首页] [上页] [下页] [尾页]
*/
function
subPageCss1(){
$subPageCss1Str
=
""
;
$subPageCss1Str
.=
"共"
.
<code class="php variable">$this->nums.
"条记录,"
;
$subPageCss1Str
.=
"每页显示"
.
<code class="php variable">$this->each_disNums.
"条,"
;
$subPageCss1Str
.=
"当前第"
.
<code class="php variable">$this->current_page.
"/"
.
<code class="php variable">$this->pageNums.
"页
"
;
if
(
<code class="php variable">$this->current_page > 1){
$firstPageUrl
=
<code class="php variable">$this->subPage_link.
"1"
;
$prewPageUrl
=
<code class="php variable">$this->subPage_link.(
<code class="php variable">$this->current_page-1);
$subPageCss1Str
.=
"[<a href="%24firstPageUrl">首页</a>] "
;
$subPageCss1Str
.=
"[<a href="%24prewPageUrl">上一页</a>] "
;
}
else
{
$subPageCss1Str
.=
"[首页] "
;
$subPageCss1Str
.=
"[上一页] "
;
}
if
(
<code class="php variable">$this->current_page <code class="php variable">$this
->pageNums){
$lastPageUrl
=
<code class="php variable">$this->subPage_link.
<code class="php variable">$this->pageNums;
$nextPageUrl
=
<code class="php variable">$this->subPage_link.(
<code class="php variable">$this->current_page+1);
$subPageCss1Str
.=
" [<a href="%24nextPageUrl">下一页</a>] "
;
$subPageCss1Str
.=
"[<a href="%24lastPageUrl">尾页</a>] "
;
}
else
{
$subPageCss1Str
.=
"[下一页] "
;
$subPageCss1Str
.=
"[尾页] "
;
}
echo
$subPageCss1Str
;
}
/*
构造经典模式的分页
当前第1/453页 [首页] [上页] 1 2 3 4 5 6 7 8 9 10 [下页] [尾页]
*/
function
subPageCss2(){
$subPageCss2Str
=
""
;
$subPageCss2Str
.=
"当前第"
.
<code class="php variable">$this->current_page.
"/"
.
<code class="php variable">$this->pageNums.
"页
"
;
if
(
<code class="php variable">$this->current_page > 1){
$firstPageUrl
=
<code class="php variable">$this->subPage_link.
"1"
;
$prewPageUrl
=
<code class="php variable">$this->subPage_link.(
<code class="php variable">$this->current_page-1);
$subPageCss2Str
.=
"[<a href="%24firstPageUrl">首页</a>] "
;
$subPageCss2Str
.=
"[<a href="%24prewPageUrl">上一页</a>] "
;
}
else
{
$subPageCss2Str
.=
"[首页] "
;
$subPageCss2Str
.=
"[上一页] "
;
}
$a
=
<code class="php variable">$this->construct_num_Page();
for
(
$i
=0;
$i
<code class="php functions">count
(
$a
);
$i
++){
$s
=
$a
[
$i
];
if
(
$s
==
<code class="php variable">$this->current_page ){
$subPageCss2Str
.=
"[<span style="color:red;font-weight:bold;">"</span>
.
$s
.
"]"
;
}
else
{
$url
=
<code class="php variable">$this->subPage_link.
$s
;
$subPageCss2Str
.=
"[<a href="%24url">"</a>
.
$s
.
"]"
;
}
}
if
(
<code class="php variable">$this->current_page <code class="php variable">$this
->pageNums){
$lastPageUrl
=
<code class="php variable">$this->subPage_link.
<code class="php variable">$this->pageNums;
$nextPageUrl
=
<code class="php variable">$this->subPage_link.(
<code class="php variable">$this->current_page+1);
$subPageCss2Str
.=
" [<a href="%24nextPageUrl">下一页</a>] "
;
$subPageCss2Str
.=
"[<a href="%24lastPageUrl">尾页</a>] "
;
}
else
{
$subPageCss2Str
.=
"[下一页] "
;
$subPageCss2Str
.=
"[尾页] "
;
}
echo
$subPageCss2Str
;
}
}
?>
演示代码:
<?php
require_once
(
"SubPages.php"
);
//每页显示的条数
$page_size
=20;
//总条目数
$nums
=1024;
//每次显示的页数
$sub_pages
=10;
//得到当前是第几页
$pageCurrent
=
$_GET
[
"p"
];
//if(!$pageCurrent) $pageCurrent=1;
$subPages
=
new
SubPages(
$page_size
,
$nums
,
$pageCurrent
,
$sub_pages
,
"test.php?p="
,2);
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

The activation process on Windows sometimes takes a sudden turn to display an error message containing this error code 0xc004f069. Although the activation process is online, some older systems running Windows Server may experience this issue. Go through these initial checks, and if they don't help you activate your system, jump to the main solution to resolve the issue. Workaround – close the error message and activation window. Then restart the computer. Retry the Windows activation process from scratch again. Fix 1 – Activate from Terminal Activate Windows Server Edition system from cmd terminal. Stage – 1 Check Windows Server Version You have to check which type of W you are using
