search
HomeBackend DevelopmentPHP Tutorial请问一个数据分页的问题

比如数据有几万条,分页的话,如果每页50条,共有几千页,每页生成html文件。
每添加一条数据就需要把这几千个html都更新一遍,以保证第一个html是最新的数据。
感觉太浪费,有没有更好的方法?


回复讨论(解决方案)

每增加一条数据 难道不是最后一个页面生成HTML吗?你的逻辑是什么.....

他的逻辑是最新的数据显示在第一页,原本每页的最后一条数据都要移动到下一页的第一条。

我觉得应该不是生成静态页面,用的伪静态,或者异步方式获取数据

这种建议不要作为静态的,这种最好做成实时的,ajax查询比较好,根据分页参数,来查询所在的50条数据

cms系统就是你说的这样的,我是这样理解的,虽然你的php生成了栏目页面耗费资源,但是如果用户有10000万甚至更多的时候效益也很高啊,他们访问不会占用你的php系统而是直接访问的静态页面。所以用户多了这样好,用户少了还是直接伪静态。我们公司的资讯网站现在用的就是你说的方法,编辑每次发布文章就得全部生成下,但是网站一点不卡

每增加一条数据 难道不是最后一个页面生成HTML吗?你的逻辑是什么.....



我是想,这样的话最后一页会不够50条数据。

这是个静态文件生成策略问题:
如果每次(有新内容时)不是重新生成所有的列表页,而只是重新生成前若干页(比如10页)
这样在新增内容50条后,从原11页起就不需要重新生成了
当然,如果期间翻页到10页之后,可能是要丢失一些资料的,但浏览的数据很多(50*10)短期内看不到也是没关系的
你也可以通过动态页来弥补这个缺失

这是个静态文件生成策略问题:
如果每次(有新内容时)不是重新生成所有的列表页,而只是重新生成前若干页(比如10页)
这样在新增内容50条后,从原11页起就不需要重新生成了
当然,如果期间翻页到10页之后,可能是要丢失一些资料的,但浏览的数据很多(50*10)短期内看不到也是没关系的


请问用这个分页策略,并且每页生成html的话,显示的页码数跟html文件名的页码是不是相反的?
比如若有1000页,第一页指向page_1000.html,第二页指向page_999.html最后一页指向page_1.html

和你原来设想的并无区别!

你问的是静态文件命名吧?
可以倒序在循环里 rename

和你原来设想的并无区别!

你问的是静态文件命名吧?
可以倒序在循环里 rename



好,就用这个方案吧,
可能用户细心的话会奇怪为什么点击的是第一页,地址栏显示是1000页。哈
谢谢了!!!
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Customizing/Extending Frameworks: How to add custom functionality.Customizing/Extending Frameworks: How to add custom functionality.Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools