PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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:
<?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);
?>
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]
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]
Problem1: Same records appeared on all pages, because i used $get instead of $_GET
//Show page listings to right:---------------------------------------------------
// 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 "<a href=\"index2.php?page=".$i."\">".$i."</a> ";
}
print "... ";
} else {
//print all page numbers between number of pages and current page
for($i = ($pagenumber +1); $i < $numofpages; $i++) {
print "<a href=\"index2.php?page=".$i."\">".$i."</a> ";
}
}
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]
Everything works fine but i get one error at bottom of each page:
PHP Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0 PHP Fatal error: Unknown: Failed opening required 'C:\Inetpub\wwwroot\document_root.php' (include_path='.;C:\Program Files\PHP\includes') in Unknown on line 0
Also any hhtp or href link lines have a background border of white, how do i chnage this?
The white border on links is most likely a css issue.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Doesnt exist, how do i create this? or download this from somewhere,
Sorry for the late reply been bussy with trying to apply css to my pagination, problem is i have a pure php script as above and i get errors when i try to incl css in my script.