nysmenu Posted July 19, 2009 Share Posted July 19, 2009 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 More sharing options...
ignace Posted July 19, 2009 Share Posted July 19, 2009 phpfreaks.com provides tutorials on these subjects. Head to: http://www.phpfreaks.com and enter pagination into the search bar and you'll find a good tutorial written by Crayon Violent. Link to comment https://forums.phpfreaks.com/topic/166504-pagination-problems/#findComment-878054 Share on other sites More sharing options...
nysmenu Posted July 19, 2009 Author Share Posted July 19, 2009 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 More sharing options...
ignace Posted July 19, 2009 Share Posted July 19, 2009 if ($result > 0) { // pagination section here } $result refers to a result from a query execution (like: mysql_query()). Link to comment https://forums.phpfreaks.com/topic/166504-pagination-problems/#findComment-878094 Share on other sites More sharing options...
nysmenu Posted July 19, 2009 Author Share Posted July 19, 2009 O.K. that part I understand, but I still do not understand where and how to include. Link to comment https://forums.phpfreaks.com/topic/166504-pagination-problems/#findComment-878110 Share on other sites More sharing options...
nysmenu Posted July 19, 2009 Author Share Posted July 19, 2009 O,K, I got the code to work. One problem, I am not getting new info from page to page. Any suggestions? Thanks Link to comment https://forums.phpfreaks.com/topic/166504-pagination-problems/#findComment-878288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.