The biggest problem we encountered in the design of the message board is how to make the message board have a page turn function and can 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, I won’t talk about it here. Let’s explain each statement in detail below.
<?
.
.
.
$query="select * from note order by sendtime desc"; #Sort messages by time
$total=mysql_numrows($result);# Calculate how many messages are there in total
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 in $show[0], and the second one is in $show[1]...
}
if(!$page){$page=0;} #Assign a value to the number of pages. If it has been assigned, it will not move. This is the only way to call this page ten design again.
$eachpage=Arbitrary number; #Number of messages that you hope are displayed without pages
$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, the number of rows in the database of the first statement changed page is $page*$eachpage, that is, "1*number of messages displayed on each page"
$end=$start+$eachpage;# Here is the number of rows in the database for the last row of the page that is changed
if($end>$total) {$end=$total;}#If you turn to the last page, the last line is often not "$start+$eachpage", but the last line in the database
$totalpage=ceil($total/$eachpage);#This is a statement that calculates the number of pages, ceil() is a rounding function
?>
.
.
.
<?
for($i=$start;$i<$end;$i++){#It's time to really start displaying the content, loop from the first line of the page to the last line of the page change
echo '<td width="450" valign="top" align="left"><font face="KaiTi_GB2312" color="#000066">';# Put the message in the table, it will look better and you can add decorations at will
echo $show[$i][content];#Show the content of the corresponding message
echo '</font></td>';
}
if($page>0){$pagenow=$page-1;?>#Set $pagenow to be 1 smaller than $page. This is to go to a page that is 1 smaller than the current page when the user clicks on "Previous Page". Because the $page of "Page1" is 0, the "Previous Page" link will only be displayed when the $page is greater than 0.
<a href=<?echo "'Message Board.php?qqname=$qqname&serial=$serial&page=$pagenow'";?>>Previous Page</a> #Show the link to "Previous Page" and pass the value. When "Message Board.php" is called again, the $page value will be the value of $pagenow in this page
<?}
if($end!=$total){$pagenow=$page+1;?>#Set $pagenow to be 1 larger than $page. As long as "$end" does not equal "$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> #Show the link to "Previous Page" and pass the value
<?}?>#Program End
The above is the solution to turning pages. You can add some pictures according to your hobbies, so that your message board will be more beautiful!
First, connect to the database, I won’t talk about it here. Let’s explain each statement in detail below.
<?
.
.
.
$query="select * from note order by sendtime desc"; #Sort messages by time
$total=mysql_numrows($result);# Calculate how many messages are there in total
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 in $show[0], and the second one is in $show[1]...
}
if(!$page){$page=0;} #Assign a value to the number of pages. If it has been assigned, it will not move. This is the only way to call this page ten design again.
$eachpage=Arbitrary number; #Number of messages that you hope are displayed without pages
$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, the number of rows in the database of the first statement changed page is $page*$eachpage, that is, "1*number of messages displayed on each page"
$end=$start+$eachpage;# Here is the number of rows in the database for the last row of the page that is changed
if($end>$total) {$end=$total;}#If you turn to the last page, the last line is often not "$start+$eachpage", but the last line in the database
$totalpage=ceil($total/$eachpage);#This is a statement that calculates the number of pages, ceil() is a rounding function
?>
.
.
.
<?
for($i=$start;$i<$end;$i++){#It's time to really start displaying the content, loop from the first line of the page to the last line of the page change
echo '<td width="450" valign="top" align="left"><font face="KaiTi_GB2312" color="#000066">';# Put the message in the table, it will look better and you can add decorations at will
echo $show[$i][content];#Show the content of the corresponding message
echo '</font></td>';
}
if($page>0){$pagenow=$page-1;?>#Set $pagenow to be 1 smaller than $page. This is to go to a page that is 1 smaller than the current page when the user clicks on "Previous Page". Because the $page of "Page1" is 0, the "Previous Page" link will only be displayed when the $page is greater than 0.
<a href=<?echo "'Message Board.php?qqname=$qqname&serial=$serial&page=$pagenow'";?>>Previous Page</a> #Show the link to "Previous Page" and pass the value. When "Message Board.php" is called again, the $page value will be the value of $pagenow in this page
<?}
if($end!=$total){$pagenow=$page+1;?>#Set $pagenow to be 1 larger than $page. As long as "$end" does not equal "$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> #Show the link to "Previous Page" and pass the value
<?}?>#Program End
The above is the solution to turning pages. You can add some pictures according to your hobbies, so that your message board will be more beautiful!