PHP+MySQL paging display example analysis_PHP tutorial
Web development (occupies a large proportion in current program development) will be the mainstream of distributed program development in the future, and ordinary web development (occupies a large proportion in current program development) The proportion of ) all involves dealing with the database. The client reads from the server and is usually displayed in the form of paging. Reading page by page is both convenient and beautiful. Therefore, writing paging programs is an important part of web development (which occupies a large proportion in current program development) . Here, we will study the writing of paging programs together.
1. Principle of paging program
The paging program has two very important parameters: how many records are displayed on each page ($pagesize) and what page is the current page ($page). With these two parameters, we can easily write a paging program. We use the MySQL(the best combination with PHP) database as the data source. In the MySQL(the best combination with PHP) (Best combination) If you want to retrieve a specific piece of content in the table, you can use the T-SQL statement: select * from table limit offset, rows to achieve this. The offset here is the record offset, and its calculation method is offset=$pagesize*($page-1), rows is the number of records to be displayed, here is $page. In other words, the statement select * from table limit 10,10 means to take out the 20 records starting from the 11th record in the table.
2. Main code analysis
$pagesize=10; //Set the number of records displayed on each page
$conn=MySQL(The best combination with PHP )_connect("localhost","root",""); //Connect to the database
$rs=MySQL(The best combination with PHP)_query("select count( *) from tb_product",$conn); //Get the total number of records $rs
$myrow = MySQL(The best combination with PHP)_fetch_array($rs);
$numrows =$myrow[0];
//Calculate the total number of pages
$pages=intval($numrows/$pagesize);
//Judge the page number setting
if (isset($_GET[page])){
$page=intval($_GET[page]);
}
else{
$page=1; / / Otherwise, set to the first page
}
3. Create use case table myTable
create table myTable(id int NOT NULL auto_increment, news_title varchar(50), news_cont text, add_time datetime,Prima(The most complete virtual host management system)RY KEY(id))
IV. Complete code
<html>
<head>
<title>php(as the current mainstream development language)Paging example</title>
<meta http-equiv="Content-Type" content="text/html; charset =gb2312">
</head>
<body>
<?php(as the current mainstream development language)
$conn=MySQL(The best combination with PHP)_connect("localhost","root","");
//Set the number of records displayed on each page
$pagesize=1;
MySQL(The best combination with PHP)_select_db("mydata",$conn);
//Get the total number of records $rs, and calculate the total number of pages with
$rs= MySQL(The best combination with PHP)_query("select count(*) from tb_product",$conn);
$myrow = MySQL(The best combination with PHP )_fetch_array($rs);
$numrows=$myrow[0];
//Calculate the total number of pages
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
$pages++;
//Set the number of pages
if (isset($_GET[page])){
$page=intval($_GET[ page]);
}
else{
//Set to the first page
$page=1;
}
//Calculate the record offset
$offset =$pagesize*($page - 1);
//Read the specified number of records
$rs=MySQL(The best combination with PHP)_query("select * from myTable order by id desc limit $offset,$pagesize",$conn);

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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



This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

Indentation specifications and examples of Go language Go language is a programming language developed by Google. It is known for its concise and clear syntax, in which indentation specifications play a crucial role in the readability and beauty of the code. effect. This article will introduce the indentation specifications of the Go language and explain in detail through specific code examples. Indentation specifications In the Go language, tabs are used for indentation instead of spaces. Each level of indentation is one tab, usually set to a width of 4 spaces. Such specifications unify the coding style and enable teams to work together to compile

Cockpit is a web-based graphical interface for Linux servers. It is mainly intended to make managing Linux servers easier for new/expert users. In this article, we will discuss Cockpit access modes and how to switch administrative access to Cockpit from CockpitWebUI. Content Topics: Cockpit Entry Modes Finding the Current Cockpit Access Mode Enable Administrative Access for Cockpit from CockpitWebUI Disabling Administrative Access for Cockpit from CockpitWebUI Conclusion Cockpit Entry Modes The cockpit has two access modes: Restricted Access: This is the default for the cockpit access mode. In this access mode you cannot access the web user from the cockpit

As a fast and efficient programming language, Go language is widely popular in the field of back-end development. However, few people associate Go language with front-end development. In fact, using Go language for front-end development can not only improve efficiency, but also bring new horizons to developers. This article will explore the possibility of using the Go language for front-end development and provide specific code examples to help readers better understand this area. In traditional front-end development, JavaScript, HTML, and CSS are often used to build user interfaces

"Understanding VSCode: What is this tool used for?" 》As a programmer, whether you are a beginner or an experienced developer, you cannot do without the use of code editing tools. Among many editing tools, Visual Studio Code (VSCode for short) is very popular among developers as an open source, lightweight, and powerful code editor. So, what exactly is VSCode used for? This article will delve into the functions and uses of VSCode and provide specific code examples to help readers

Application and example analysis of PHP dot operator In PHP, the dot operator (".") is an operator used to connect two strings. It is very commonly used and very flexible when concatenating strings. By using the dot operator, we can easily concatenate multiple strings to form a new string. The following will introduce the use of PHP dot operators through example analysis. 1. Basic usage First, let’s look at a basic usage example. Suppose there are two variables $str1 and $str2, which store two words respectively.
