Jump to content

Pagination problems


nysmenu

Recommended Posts

Hi, I am new at PHP. I need to make a pagination on my site and here's a code that seems to be working but when I go into different pages I get a message that says "page not found". Can someone please help me with this. Thanks.

 

<?php
$username="pass";
$password="pass";
$database="mysql";

$dbh=mysql_connect(localhost,$username,$password) or die ('I cannot connect to the database because: ' . mysql_error());
@mysql_select_db($database);


$result = mysql_query("SELECT COUNT(*) AS total_entries FROM help_topic") or die(mysql_error());
$row = mysql_fetch_row($result);


$total_entries = $row[0];



$entries_per_page = 25;


if(isset($_GET['currentpage'])) {
$page_number = $_GET['currentpage'];
} else {
$page_number = 1;
}



$total_pages = ceil($total_entries / $entries_per_page);


$offset = ($page_number - 1) * $entries_per_page;


$result = mysql_query("SELECT * FROM help_topic LIMIT $offset, $entries_per_page") or die(mysql_error());
while($obj = mysql_fetch_array($result)) {
// Display the data however you want here.
print $obj ['url'];
echo "<br>";
}


for($i = 1; $i <= $total_pages; $i++) {
if($i == $page_number) {
// This is the current page. Don't make it a link.
print "$i ";
}else {
// This is not the current page. Make it a link.
print "<a href=\"untitled.php?page_number=$i\">$i</a> ";
} 
}
?>

 

The first page shows this on the bar: http://localhost/websites/sun/Untitled-1.php which is good

 

bu the other pages show this: http://localhost/websites/sun/untitled.php?page_number=2

Not Found

 

The requested URL /websites/sun/untitled.php was not found on this server.

 

I really appreciate your help...

Link to comment
https://forums.phpfreaks.com/topic/166504-pagination-problems/
Share on other sites

Thank you for your reply. I had found that tutorial already, unfortunately I don't quite understand this too well. I tried using the script CV posted but I couldn't get it to work. I found the one I need help on but I can't figure out some things. Someone else posted a comment on CV's script similar to my problem and CV answered it with this:

 

    Just wrap a condition around the whole pagination section.

 

    if ($result > 0) {

    // pagination section here

    }

 

I don't understand what to include in there or where. Can someone show me please? Thanks

Link to comment
https://forums.phpfreaks.com/topic/166504-pagination-problems/#findComment-878072
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.