search
HomeBackend DevelopmentPHP TutorialDetailed explanation of the implementation of message board page turning_PHP tutorial

Detailed explanation of the implementation of message board page turning_PHP tutorial

Jul 21, 2016 pm 04:05 PM
Functionexisthowaccomplishusmostmessage boardofTurn pagedesignDetailed explanationmeet

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{
$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
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment