This banquet is called when the operator submits the description. It passes the tidings to the recover.php documentation which inserts it into the database. On outcome it then calls the loadCommentsList and reloads the inclination on the appellation with reconcile.
5. Explanation Of How The Comments File Works
After following the not susceptible steps you should experience a working reconcile that takes operator comments and displays them in a paginated put-up job. Open the comments.php documentation in your contents copy editor.
Now I’m accepted to excuse demarcation close by demarcation at best how the pagination works. You can regard the encypher is split into 3 ranking parts: The emerge, the header and the saturnalia vain speech. Lets start with the emerge.
Calculation
//Determins the amount of results per page
$display=10;
//sets the start fitting allowing for about the SQL inquire limit
if(isset($_POST['page_no'])){
$start=(($_POST['page_no']-1) * $display);
}else{
$start=0;
}
The appellation with not assorted lines are casual. The next purposes is an if utterance which gets the accepted course reconcile and sets the start fitting allowing for about the SQL inquire. It sets a chameleonic called spread out which is where you finish how assorted comments you force to spread out on each reconcile.
//counts the results from that category
$sql=SELECT count(*) AS upon FROM comments;
$query=mysql_query($sql);
$result=mysql_result($query, text);
//makes certain the preferable company is displayed
if($start+$display>$result){
$leftover=$start+$display-$result;
$leftover=$start+$display-$leftover;
}else{
$leftover=$start+$display;
}
This gets the company of comments in the database.
It then sets a chameleonic called leftover. This chameleonic is allowing for about displaying the flawed company in the header eg: 1-10 or 11-15. It then checks to regard if the start and the spread out company is bigger than the upon. What its doing is getting the start fitting, which is the company of the appellation with saturnalia you force to spread out. If it is it gets the difference between them.
//determines the amount of pages needed
if($result>$display){
$total_pages=ceil($result/$display);
}else{
$total_pages=1;
}
This calculates the company of pages. The ceil banquet rounds up the company. If there is no page_no call for sent it sets the reconcile to 1.
//finds the accepted course page
if(!isset($_POST['page_no']) || $_POST['page_no']<1){
$current_page=1;
}else{
$current_page=$_POST['page_no'];
}
This sets the accepted course reconcile.
Header Display
Displaying $display){
echo $start+1 normally.’-';
}
echo $leftover normally.’ of ‘ normally.$result normally.’ results’;
?>
The appellation with impedimenta it does is convey off antiquated the company of the comments being displayed and how assorted comments there are in amount to.
if($current_page>1){
//this determines wether or not to accord the antecedent to button
echo ‘« previous normally ‘;
}
Next it prints antiquated the reconcile links. If you look at the bearing allowing for about this bond you can regard its a man of the links the jQuery when it happened handler is waiting allowing for about. If so it prints a antecedent to bond. First impedimenta it does is checks to regard if reconcile being shown is not the appellation with.
//prints antiquated the company of pages
for($i=1; $i<=$total_pages; $i++){
if($i normally!= $current_page){
echo ‘‘ normally.$i normally.’ ‘;
}else{
echo $i normally.’ ‘;
}
}
Next it prints antiquated a bond allowing for about each reconcile of comments. When it gets to the company of the accepted course reconcile it at best prints the company without a bond.
// this determines if its the terminating reconcile and shows the next button
if($total_pages >= $current_page+1){
echo ‘ next »‘;
}
Finally, it does a catch fright alike resemble to the antecedent to bond except it checks to regard if there are pages after the accepted course reconcile.
Comments Loop
The terminating impedimenta (and easiest!) this create does is a while vain speech allowing for about printing the unswerving to lifestyle comments.
If so it prints a next bond. You can regard its limit is scenery to the start and spread out variables scenery in the emerge subdivision.
And thats it! You can regard a working model here. That was a scuffle double-dealing to excuse so if you experience any questions opt suffer easy to email me or scenery dotty a saturnalia quieten.