Home php教程 php手册 php中文本数据翻页(留言本翻页)_php基础

php中文本数据翻页(留言本翻页)_php基础

May 17, 2016 am 09:10 AM

在mysq中介绍翻页的文章不少,而文本数据表格式的翻页介绍的很少,这里我就简单的说一下翻页

主要介绍以下翻页思想
1、留言本的翻页
2、文本论坛的翻页

————————————————————————
留言本的翻页:
——————————————————————————————
这个在文本数据表中的翻页是最简单的翻页,这样说明一下

golbal file
    Data.dat    ---    NOTE FILE USE
    user.dat    ---     Forum File use
Data.dat
_______________________________________________________________________
[1]    [POSTUSER]     [TITLE]        [MEM]        [POSTTIME]    [IP]
[2]    [POSTUSER]     [TITLE]        [MEM]        [POSTTIME]    [IP]
[3]    [POSTUSER]     [TITLE]        [MEM]        [POSTTIME]    [IP]
[4]    [POSTUSER]     [TITLE]        [MEM]        [POSTTIME]    [IP]
[5]    [POSTUSER]     [TITLE]        [MEM]        [POSTTIME]    [IP]

说明:
     其中的[1,2,3,4,5....]是我自己添加进去的,主要是为了大家更好的理解

index.php source:.

__________________________________________________

---====BOF====---

$file            =        "data.dat";        //数据文件
if(file_exits($file)){                        //容错处理,防止无数据文件存在
    $fp=fopen($file,"w+");
    fclose($fp);
    unset($fp);
}
$listnumber        =        20;            //每页显示条数
$fp            =        file($file);        //读取数据到内容中
$number            =        count($fp);        //计算总数据量
$pagenumber        =        floor($number/$listnumber)+1;
if($number    print "暂时无记录,欢迎留言";
    /*+--------------------------------+
          |在这里打印FORM表单或连接到表但的|
          | URL,               |
          +--------------------------------+*/
}else{
    if(empty($_POST["page"])){                //这段IF...ELSE...是为了兼容php4.20的默认设置,防止出现无效的全局变量而写的
        $page        =    0;            //因为是从数据文本读出来的,保存在数组中,有个O下标
    }else{
        $page        =    $_POST["page"]
    }

    if($pagepagenumber){            //检错处理,当页面参数跳出总页面或小于首页(0)的时候,将返回到第一页
        $page=0;
    }

    $startnote    =    $page*$listnumber;        //开始记录位置
    $endnote    =    $startnote+$listnumber;        //结束记录位置

    //for($int_a=$startnote;$int_a
    pirnt "

"

    for($int_a=$endnote;$int_a>=$startnote;$int_a--){    //排序显示类似DESC模式
        $info=explode("\t",$fp[$int-a]);        //切割数据获得每条记录的详细数据我这里是用了一个TAB键分割
        print "
用户:$info[1] 标题$info[2] 发言内容:$info[3] 发布时间:$info[4] IP:$info[5]";
    }

    $prevpage    =    $page-1;            //上一页的PAGE数
    $nextpage    =    $page+1;            //下一页的page数

    print "

    首页
    上一页
    下一页
    尾页
    
";                        //这里您可以直接将页面的检测加到这里,那样给别人看的是舒服的,但是效果是一样的
                                //例如:这里有可能出现20页出现        下一页    或
}
?>
---====EOF====---


写的仓促,另外中间有不少因为考虑到使用PHP4.20所以就改变了一下,比如说PHP_SELF已经采用_SERVER["PHP_SELF"]等
Statement of this Website
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

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

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)