


PHP reads mysql database data and implements paging example code_PHP tutorial
PHP reads mysql database data and implements paging example code as follows:
- //Connect to the database
- $db =mysql_connect("localhost","root","root");
- mysql_select_db("gaoge",$db);
- //Set the number of records displayed on each page
- $pagesize=3;
- //Get the total number of records and calculate the total number of pages
- $res=mysql_query("select count(*) from image " ,$db);
- $myrow = mysql_fetch_array($res);
- //$myrow[o] is the sum of the total number of records in the database
- $numrows=$myrow[0];
- //echo "total num is:";
- //echo $numrows;
- // echo
; - //Calculate the total number of pages
- $pages=intval($numrows/$pagesize);
- if ($numrows%$pagesize )
- $pages ;
- // echo "total pages is:";
- //echo $pages;
- //echo
; - //Determine whether the page number is set or not, if not, it is defined as the home page
- if (isset($_GET[page])){
- //echo "page exist";
- $page = $_GET[page];
- //echo "enter if ";
- }
- else{
- //echo "page not exist";
- $page = 1;
- }
- //echo "page is:" ;
- // echo $page;
- // echo
; - //Calculate record bias Offset
- $offset=$pagesize*($page-1);
- // echo "offset is:" ;
- echo $offset;
- //Get records
- $res=mysql_query("select * from image order by id desc limit $offset,$pagesize" ,$db);
- //Loop display records
- if ($myrow = mysql_fetch_array($res))
- {
- $i=0;
- ?>
- < ;table cellspacing=0 bordercolordark=#FFFFFF width="95%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">
-
ID Picture name Uploader name Upload time Picture effect - do {
- $i ;
- ?>
-
-
< ?php echo $myrow[2];?> -
-
- }
- while ($myrow = mysql_fetch_array ($res));
- echo "" ;
- }
- //Display the total number of pages
- echo "There are ".$pages." pages (".$page."/".$pages.")";
";- //Display the number of pages
- for ($i=1;$i<=$pages;$i)
- echo "< ;a href=pages.php?page=".$i.">Page ".$i ." ";
- //echo "page is:";
- //echo "$page";
- // echo "
";- //Display the page number
- echo "
- //Calculate the page values of the first page, previous page, next page and last page
- $ first=1;
- $prev=$page-1;
- $next=$page 1;
- $last=$pages;
- echo "Homepage ";
- //echo "page is:";
- //echo "$page";
- echo "Previous page ";
- echo "Next page ";
- echo "Last page ";
- echo "";
- echo "
- ?>

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











session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

Composer is a dependency management tool for PHP, and manages project dependencies through composer.json file. 1) parse composer.json to obtain dependency information; 2) parse dependencies to form a dependency tree; 3) download and install dependencies from Packagist to the vendor directory; 4) generate composer.lock file to lock the dependency version to ensure team consistency and project maintainability.

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

Use the EXPLAIN command to analyze the execution plan of MySQL queries. 1. The EXPLAIN command displays the execution plan of the query to help find performance bottlenecks. 2. The execution plan includes fields such as id, select_type, table, type, possible_keys, key, key_len, ref, rows and Extra. 3. According to the execution plan, you can optimize queries by adding indexes, avoiding full table scans, optimizing JOIN operations, and using overlay indexes.
