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
<?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