Have created php/mysql pagination but have minor issue:
Posted: Tue Oct 16, 2007 3:48 pm
scottayy | Please use
Thanks in Advance
Tovia
scottayy | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi Tovia here
I have three issues with my pagination, pls help:
1- The same records appear on every page, eg 123 on page 1, and 123 on page 2., which should have 456.
2- The current page isnt in bold in the number listing
3- The numbers to the right of the current page dont appear
My Code is as follows, really need to finish this soon:Code: Select all
<?PHP
// user credentials
$host = "localhost";
$user = "root";
$pass = "police";
$data = "test";
// Establish connection, and select db
$conn = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($data, $conn) or die(mysql_error());
//create some variables
$pagenumber = (isset($GET["page"]) && is_numeric($GET["page"])) ? $GET["page"] : 1;
//establish number of resulsts per page
$perpage = 5;
//establish a padding value
$padding = 10;
// get start index of results
$startindex = ($pagenumber * $perpage) - $perpage;
// get total number of dbms entries
$totalcount = "SELECT COUNT(*) as 'Total' FROM test.articles";
$rscount = mysql_query($totalcount, $conn) or die(mysql_error());
$rowcount = mysql_fetch_object($rscount);
//Show page listings
print "
";
// get our total number of pages
$numofpages = ceil($rowcount->Total / $perpage);
// print link to first page
print "FIRST ";
// if our current page, minus our padding is greater than 1
if (($pagenumber - $padding) > 1) {
print "... ";
// set our lower limit
$lowerlimit = $pagenumber - $padding;
// print all padded numbers between lowerlimit and current page
for($i = $lowerlimit; $i < $pagenumber; $i++) {
print "".$i." ";
}
} else {
// print all numbers between current page, and first page
for($i = 2; $i < $pagenumber; $i++) {
print "".$i." ";
}
}
// if were not on the first page, or the last page, print current page
if(($pagenumber !=0) && ($pagenumber !=1) && ($pagenumber != $numofpages))
{ print " - " . $pagenumber . " - "; }
// if our current page, plus our padding , is less than the total number of pages
if (($pagenumber + $padding) < $numofpages) {
// set upper limit
$upperlimit = $pagenumber + $padding;
// print all numbers from padded pages above current page
for($i = ($pagenumber + 1); $i <= $upperlimit; $i++) {
print "".$i." ";
}
print "... ";
} else
//print all page numbers between number of pages and current page
for($i = ($pagenumber +1); $i < $numofpages; $i++) {
print "".$i." ";
}
// print link to last page
print "LAST";
print "";
// get page results
$sql = "SELECT id,body FROM test.articles ORDER BY timestamp1
LIMIT $startindex, $perpage";
echo $startindex;
// get result set
$rs = mysql_query($sql,$conn) or die(mysql_error());
// do we have results
if (mysql_num_rows($rs) > 0) {
// show the results
while ($row = mysql_fetch_object($rs)) {
print "
";
print $row->id;
print ": ";
print $row->body;
print ": ";
print "";
}
} else {
print "Sorry, no results found.";
}
//close our dbms connection
mysql_close($conn);
?>Thanks in Advance
Tovia
scottayy | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]