In the design of the message board, the biggest problem we encounter is how to enable the paging function of the message board and automatically determine whether the last page is reached, here I will share with you the technologies I used in designing the message board:
Connect to the database first. I will not talk about it here. The following describes each statement in detail.
<?
.
.
.
$ Query = "select * from note order by sendtime desc"; # sort messages by Time
$ Total = mysql_numrows ($ result); # calculate the total number of messages
For ($ I = 0; $ I <$ total; $ I ++) # assign each message content to a function.
{
$ Show [$ I] = mysql_result ($ result, $ I, "message content"); # in this way, the first message is displayed in $ show [0, the second entry is in $ show [1...
}
If (! $ Page) {$ page = 0 ;}# assign a value to the number of pages. If this value has already been assigned, it will not move. This is the only one that calls this page again.
$ Eachpage = any number; # number of messages that you want to display without pages
$ Start = $ page * $ eachpage; # Here is the number of rows of the first statement displayed on each page in the database. For example, if you go to the second page, the number of rows in the database of the first statement on the page is changed to $ page * $ eachpage, that is, "1 * Number of messages displayed on each page"
$ End = $ start + $ eachpage; # the number of rows in the database of the last row of the Modified PAGE
If ($ end> $ total) {$ end = $ total;} # if you flip to the last page, the last line is often not "$ start + $ eachpage ", but the last row in the database.
$ Totalpage = ceil ($ total/$ eachpage); # This is a statement used to calculate the number of pages. ceil () is the entire function.
?>
.
.
.
<?
For ($ I = $ start; $ I <$ end; $ I ++) {# It's time to start displaying the content, from the first line of the page to the last line of the page
Echo '<td width = "450" valign = "top" align = "left"> <font face = "_ GB2312" color = "#000066"> '; # Put the message in the table, which looks nice and can be decorated as needed
Echo $ show [$ I] [content]; # display the corresponding message content
Echo '</font> </td> ';
}
If ($ page> 0) {$ pagenow = $ page-1;?> # Set $ pagenow to 1 smaller than $ page to go to a page 1 smaller than the current page when you click "Previous page, because the $ page of "1st page" is 0, the "Previous page" link is displayed only when the $ page is greater than 0.
<A href = <? Echo "'message board. php? Qqname = $ qqname & serial = $ serial & page = $ pagenow' ";?>> Previous page </a> # display the link of "Previous page" and pass the value. When "message board. php" is called again, the value of $ page is the value of $ pagenow on this page.
<?}
If ($ end! = $ Total) {$ pagenow = $ page + 1;?> # Set $ pagenow to 1 larger than $ page. If "$ 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.
<A href = <? Echo "'message board. php? Qqname = $ qqname & serial = $ serial & page = $ pagenow' ";?>> Next page </a> # display the link of "Previous Page" and pass the value
<?}?> # Program end
The above is a solution for turning pages. You can add some pictures and so on based on your hobbies, so that your message board will be more beautiful!