使用相关函数实现PHP处理分页
通过对
如我们指定分页时,每页20篇。某子频道列表内文章经数据库查询为45条,则,首先我们通过查询得到如下参数:1,总页数;2,每页篇数。
PHP处理分页第二 步,for ($i = 0; $i
- ?php
- $fp = fopen ("temp.html","r");
- $content = fread ($fp,filesize ("temp.html"));
- $onepage = '20';
-
$sql = "select id from article where
channel='$channelid'"; - $query = mysql_query ($sql);
- $num = mysql_num_rows ($query);
- $allpages = ceil ($num / $onepage);
- for ($i = 0;$i$allpages; $i++){
- if ($i == 0){
- $indexpath = "index.html";
- } else {
- $indexpath = "index_".$i."html";
- }
- $start = $i * $onepage;
- $list = '';
-
$sql_for_page = "select name,filename,title
from article where channel='$channelid'
limit $start,$onepage"; - $query_for_page = mysql_query ($sql_for_page);
- while ($result = $query_for_page){
-
$list .= '.$root.$result['filename']
.' target=_blank>'.$title.'a>br>'; - }
-
$content = str_replace ("{articletable}
",$list,$content); - if (is_file ($indexpath)){
- @unlink ($indexpath); //若文件已存在,则删除
- }
-
$handle = fopen ($indexpath,"w");
//打开文件指针,创建文件 - /*
- 检查文件是否被创建且可写
- */
- if (!is_writable ($indexpath)){
- echo "文件:".$indexpath."不可写,
请检查其属性后重试!"; //修改为echo - }
- if (!fwrite ($handle,$content)){ //将信息写入文件
- echo "生成文件".$indexpath."失败!"; //修改为echo
- }
- fclose ($handle); //关闭指针
- }
- fclose ($fp);
- die ("生成分页文件完成,如生成不完全,
请检查文件权限系统后重新生成!"); - ?>
大致PHP处理分页的思路如此,其中如其它数据生成,数据输入输出检查,分页内容指向等可酌情在页面中加入。

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools
