Home  >  Article  >  Backend Development  >  Detailed explanation of the implementation of message board page turning_PHP tutorial

Detailed explanation of the implementation of message board page turning_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:05:06864browse

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 technology I used when designing the message board. :
First connect to the database, which I won’t go into here. Each statement will be explained in detail below.
.
. .
. result);#Calculate how many messages there are in total
for ($i=0; $i<$total; $i++) #Assign the content of each message to a function
{
$show[ $i]=mysql_result($result,$i,"Message content");#In this way, the first message is in $show[0], and the second message is in $show[1]...
}
if(!$page){$page=0;} #Assign a value to the page number. If it has already been assigned, it will not move. This is the only way to call this page again.
$eachpage=any Number; #The number of messages you want to display on no page
$start=$page*$eachpage;#Here is the number of rows in the database of the first statement displayed on each page. For example, if the user turns to the second page, then The number of rows in the database of the first statement to change the page is $page*$eachpage, that is, "1*the number of messages displayed on each page"
$end=$start+$eachpage;#This is the last line of the page change Number of rows in the database
if($end>$total) {$end=$total;}#If you turn to the last page, the last row is often not "$start+$eachpage", but the number in the database The last line
$totalpage=ceil($total/$eachpage);#This is a statement to calculate the number of pages. ceil() is the rounding function
?>
. .
.
            . The last line of the page
echo '';#will Put the message in the table, it will look better, and you can add any decorations
echo $show[$i][content];#Display the content of the corresponding message
echo '

if($page>0){$pagenow=$page-1;?>#Set $pagenow to 1 less than $page, so that when the user clicks "Previous page "When you go to a page that is 1 smaller than the current page number, because the $page of "Page 1" is 0, the "previous page" link will be displayed only when $page is greater than 0
                                                      >Previous page #Display the link to "Previous page" and pass the value When calling "Message Board.php" again, the $ page value will be the value of the $ PageNow on the page
& lt ;?}
if ($ End! = $ Total) {$ PageNow = $ Page+ 1;?>#Set $pagenow to be 1 greater than $page. As long as "$end" is not equal to "$total", it means that the current page is not the last page, that is, the "next page" link is displayed
>Next page #Display "previous page" Link, and pass the value
& lt;?}? & Gt;#Program end
The above is the solution to the page turning. Even more beautiful!





http://www.bkjia.com/PHPjc/315745.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/315745.htmlTechArticleThe biggest problem we encountered in the design of the message board was how to make the message board have page turning function, and It can automatically determine whether it has reached the last page. Below I will leave a message about my design...
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