search
Homephp教程php手册留言板翻页的实现详解

留言板翻页的实现详解

Jun 13, 2016 pm 12:40 PM
Functionexisthowaccomplishusmostmessage boardofTurn pagedesignDetailed explanationmeet

我们在留言板的设计中,遇到的最大问题就是如何让留言板具有翻页功能,而且可以自动判断是否到了最后一页,下面我就将我在设计留言板时用到的技术与大家分享:
首先连接数据库,这里就不讲了,下面就将每一条语句作详细的说明。

        .
        .
        .
$query="select * from note order by sendtime desc";  #按时间将留言排序
$total=mysql_numrows($result);#计算总共有多少条留言
for ($i=0; $i{
$show[$i]=mysql_result($result,$i,"留言内容");#这样第一条留言就在$show[0]中,第二条则在$show[1]中...
}
if(!$page){$page=0;} #给页数赋值,如果已经赋过,则不动,这是唯一后再次调用此页十设计的
$eachpage=任意数; #希望没页显示的留言数
$start=$page*$eachpage;#此处是每页显示的第一条语句在数据库中的行数,比如用户翻到第二页,则改页第一条语句在数据库中的行数为$page*$eachpage,即"1*每页显示的留言数"
$end=$start+$eachpage;#此处为改页的最后一行在数据库中的行数
if($end>$total) {$end=$total;}#如果翻到了最后一页,则最后一行往往不是"$start+$eachpage",而是数据库中的最后一行
$totalpage=ceil($total/$eachpage);#这是一条计算页数的语句,ceil()是取整函数
?>
         .
         .
         .

for($i=$start;$iecho '

';#将留言放在表中,这样会比较好看,而且可以任意添加装饰
echo $show[$i][content];#显示相应留言的内容
echo '
';
}         
if($page>0){$pagenow=$page-1;?>#将$pagenow设置成比$page小1,是为了当用户点击"上一页"时去到比当前页数小1的页,因为"第1页"的$page为0,所以只有当$page大于0时才会显示"上一页"链接
      >上一页 #显示"上一页"的链接,并传递数值,当再次调用"留言板.php"时,$page值将是本页中$pagenow的值
      }       
if($end!=$total){$pagenow=$page+1;?>#将$pagenow设置成比$page大1,只要"$end"不等于"$total",就说明当前页还不是最后一页,即显示"下一页"链接
      >下一页 #显示"上一页"的链接,并传递数值
      }?>#程序结束
以上为翻页的解决办法,你可以根据自己的爱好加一些图片之类的,那样你的留言板就会更更加漂亮!

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

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
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

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.

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.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment