The simplest php pagination
The source of
<style type="text/css"> div.pagination { padding: 3px; margin: 4px; } div.pagination a { padding: 2px 5px 2px 5px; margin: 4px; border: 1px solid #666; text-decoration: none; /* no underline */ color: #666; } div.pagination a:hover, div.pagination a:active { border: 1px solid #333; color: #000; } div.pagination span.current { padding: 2px 5px 2px 5px; margin: 4px; border: 1px solid #333; font-weight: bold; background-color: #666; color: #FFF; } div.pagination span.disabled { padding: 2px 5px 2px 5px; margin: 4px; border: 1px solid #EEE; color: #DDD; } </style>
<?php $c $tbl_name="main";<span style="white-space:pre"> </span>//查询的表格 $limit=5;<span style="white-space:pre"> </span>//每页条数 $adjacents = 3; //当前页的左n页,右n页 $query = "SELECT COUNT(*) FROM $tbl_name"; $total_pages = mysqli_fetch_array(mysqli_query($conn,$query)); $total_pages = $total_pages[0]; $targetpage = "main2.php"; @$page = $_GET['page']; if($page) $start = ($page - 1) * $limit; else $start = 0; $sql = "select * from `".$tbl_name."` limit ".$start.",".$limit;//主查询语句 $result1 = mysqli_query($conn,$sql); if ($page == 0) $page = 1; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total_pages/$limit); $lpm1 = $lastpage - 1; $pagination = ""; if($lastpage > 1) { $pagination .= "<div class=\"pagination\" align=\"center\">"; if ($page > 1) $pagination.= "<a href=\"$targetpage?page=$prev\">前一页</a>"; else $pagination.= "<span class=\"disabled\">前一页</span>"; if ($lastpage < 7 + ($adjacents * 2)) { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } elseif($lastpage > 5 + ($adjacents * 2)) { if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } else { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } } if ($page < $counter - 1) $pagination.= "<a href=\"$targetpage?page=$next\">下一页</a>"; else $pagination.= "<span class=\"disabled\">下一页</span>"; $pagination.= "</div>\n"; } ?> //此处放主表格 <?=$pagination?>//显示页码
The above introduces the simplest PHP paging, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Implementing data paging and display optimization in Vue projects. In Vue projects, when a page needs to display a large amount of data, data paging and display optimization usually need to be performed to improve user experience. This article will introduce how to use Vue to implement data paging and display optimization. , and provide specific code examples. 1. Data paging Data paging refers to dividing a large amount of data into multiple pages according to certain rules and displaying them on the page. You can use the following steps to implement data paging in a Vue project: Define the data source. First, define a

Everyone is looking forward to today's Windows 1123H2 release. In fact, Microsoft has just launched updates to the release preview, which is the closest channel before the official release stage. Known as Build 22631, Microsoft said they are rolling out the new rebranded chat app, phone link, and play together widgets that have been tested on other internal channels over the past few months. "This new update will have the same servicing branch and codebase as Windows 11 version 22H2 and will be cumulative with all newly announced features, including Copilot in Windows (preview)," Microsoft promises. Redmond officials further

Detailed explanation of CSS serial number attributes: counter and list-style-type Introduction: In web design, we often encounter situations where we need to number elements such as lists or titles. In order to meet different design needs, CSS provides two important attributes: counter and list-style-type. This article will detail the usage of these two properties and provide some specific code examples. 1. Counter attribute: The counter attribute allows developers to create

Description Project Description Python Interpreter 3.10.6 Counter module In Python's collections module, a very commonly used module is Counter. Counter is a simple counter used to count the number of certain hashable objects. It stores elements and their counts in the form of a dictionary. Counter() class Counter() can count the parameters passed to this class according to certain rules, and return the results in the form of a dictionary by using the counting object and the counting result as key-value pairs. Counter(iterable=None,/,**kwds) gives an example fromcollectionsimport

Detailed explanation of CSS content attributes: content, counter and quotesCSS (cascading style sheets) is an integral part of front-end development. It can help us beautify web pages and enhance user experience. In CSS, there are some special properties that can be used to control the display of text content, including content, counter, and quotes. This article explains these properties in detail and provides specific code examples. 1. content attribute content attribute

Laravel development: How to paginate data using LaravelPagination? Laravel is a powerful PHP framework that helps developers build high-quality web applications quickly. In Laravel applications, it is often necessary to display data in pages. Laravel provides a powerful pagination class - LaravelPagination, which makes data paging very easy. In this article I will show you how to use Laravel

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没问题。
