Home > Backend Development > PHP Tutorial > Detailed explanation of the implementation of message board page turning (with code)

Detailed explanation of the implementation of message board page turning (with code)

PHPz
Release: 2018-09-30 13:47:23
Original
1631 people have browsed it

The biggest problem we encountered in the design of the message board was how to make the message board have a page turning function and automatically determine whether it has reached the last page. Below I will share with you the techniques I used when designing the message board. Share:
First connect to the database, which I won’t go into here. Here is a detailed explanation of each statement.

...
$query="select * from note order by sendtime desc";  //按时间将留言排序 
$total=mysql_numrows($result); //计算总共有多少条留言 
for ($i=0; $i<$total; $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;$i<$end;$i++){
//下面到了真正开始显示内容的时候了,从改页的第一行循环到改页最后一行 
echo &#39;&#39;; //将留言放在表中,这样会比较好看,而且可以任意添加装饰 
echo $show[$i][content]; //显示相应留言的内容 
echo &#39;&#39;; 
}    
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",就说明当前页还不是最后一页,即显示"下一页"链接 
      >下一页 #显示"上一页"的链接,并传递数值    
//程序结束
Copy after login

The above is a solution to page turning. You can add some pictures according to your own hobbies, so that your message board will be more beautiful!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template