•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 403,519 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,798 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 610 | Replies: 1 | Solved
![]() |
•
•
Join Date: May 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Hi folks,
I have a small Paging problem, was wondering if anyone could help me out with.
I have a blog that I need to page after a set number of blogs.
The Next and Previous links work fine and so does the Page number Nav. However, my page number Nav starts at 0, not 1 like it normally should.
IE
Prev 0 1 2 3 4 Next
The code I'm using was authored by www.plus2net.com
Thanks in advance, this has been driving me bonkers!
Regards
-Matthew
I have a small Paging problem, was wondering if anyone could help me out with.
I have a blog that I need to page after a set number of blogs.
The Next and Previous links work fine and so does the Page number Nav. However, my page number Nav starts at 0, not 1 like it normally should.
IE
Prev 0 1 2 3 4 Next
The code I'm using was authored by www.plus2net.com
<?php
// If you use this code with a different page ( or file ) name then change this
$page_name="futuretrips.php";
// To take care global variable if OFF
$start=$_GET['page'];
// This variable is set to zero for the first page
if(!($start > 0)) {
$start = 0;
}
$eu = ($start - 0);
// No of records to be shown per page.
$limit = 4;
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
// Find out the number of records in our table.
// Use this to break the pages
$query2=" SELECT blog_ID FROM tblBlog ";
$result2=mysql_query($query2);
echo mysql_error();
// The variable nume will store the total number of records in the table
$nume=mysql_num_rows($result2);
// Start executing the query with variables $eu and $limit set at the top of the page
$query=" SELECT * FROM tblBlog limit $eu, $limit ";
$result=mysql_query($query);
// Display the returned records
while($noticia = mysql_fetch_array($result)) {
?>
<div class="blog_title">
<h2>
<?php echo $noticia[blog_Title] ?>
</h2>
</div>
<span class="blog_subinfo">
<span class="blog_author">
by $noticia[blog_Author]
</span>
<span class="blog_timestamp">
<?php echo $noticia[blog_Date] ?> <?php echo $noticia[blog_Time] ?>
</span>
<div class="barra-footer-clearboth">
</div>
</span>
<p class="blog_body">
<?php echo $noticia[blog_Body] ?>
</p>
<?php
}
// End of displaying the table with records
// Variables set for advance paging
// This should be more than $limit and set to a value for which links to be selected
$p_limit=8;
// To take care global variable if OFF
$p_f=$_GET['p_f'];
// This variable is set to zero for the first page
if(!($p_f > 0)) {
$p_f = 0;
}
$p_fwd=$p_f+$p_limit;
$p_back=$p_f-$p_limit;
// End of variables for advance paging
// Start the bottom links with Prev and next link with page numbers
?>
<span class="body-page-container">
<span class="body-page-left">
<?php
if($p_f<>0){
print "<a href='$page_name?page=$p_back&p_f=$p_back'>Previous $p_limit</a>";
}
// if our variable $back is equal to 0 or more then only we will display the link to move back
if($back >=0 and ($back >=$p_f)) {
print "<a href='$page_name?page=$back&p_f=$p_f'>Previous</a>";
}
?>
</span>
<span class="body-page-middle">
Page
<?php
// Let us display the page links at center. We will not display the current page as a link
for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit) {
if($i <> $eu) {
$i=$i+$p_f; echo "<a href='$page_name?page=$i&p_f=$p_f'>$i</a>";
}
else {
// Current page is not displayed as link
echo "$i";
}
}
?>
</span>
<span class="body-page-right">
<?php
// If not on the last page then Next link will be displayed. Check that here
if($this1 < $nume and $this1 <($p_f+$p_limit)) {
print "<a href='$page_name?page=$next&p_f=$p_f'>Next</a>";
}
if($p_fwd < $nume) {
print "<a href='$page_name?page=$p_fwd&p_f=$p_fwd'>Next $p_limit</a>";
}
?>
</span>
<div class="footer-clearboth">
</div>
</span>
Thanks in advance, this has been driving me bonkers!
Regards
-Matthew
Last edited by Besherek : Jul 6th, 2008 at 10:40 pm.
•
•
Join Date: May 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Funny how a solutions comes to you soon after a call for help.
I'll share it for future reference, maybe someone will pick it up on google at some point.
I made a change in the middle container where the page numbering sits.
Bold points are the changes I made.
I'll share it for future reference, maybe someone will pick it up on google at some point.
I made a change in the middle container where the page numbering sits.
Bold points are the changes I made.
<span class="barra-followup-body-page-middle">
Page
<?php
// Let us display the page links at center. We will not display the current page as a link
$i=0;
$l=1;
for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit) {
if($i <> $eu) {
$i=$i+$p_f; echo "<a href='$page_name?page=$i&p_f=$p_f'>$l</a>";
}
else {
// Current page is not displayed as link
echo "$l";
}
$l=$l+1;
}
?>
</span>
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- PHP MYSQL Paging Problem (PHP)
- help plz.......... (PHP)
- How do you only display 8 rows per page? PHP/MYSQL (PHP)
- second page error (PHP)
- numbering the pages (PHP)
Other Threads in the PHP Forum
- Previous Thread: The page donot load completely untill I refresh the page
- Next Thread: How to make a forum?


Linear Mode