MDanz Posted August 13, 2009 Share Posted August 13, 2009 mysql_connect("localhost", "Master", "password"); mysql_select_db("database"); //get the number of total rows $construct = "SELECT * FROM Stacks"; $run = mysql_query($construct); // Number of records found $foundnum = mysql_num_rows($run); // Number of results per page $display = 5; if(isset($_GET['page'])) { $currentPage = $_GET['page']; } else{ $currentPage = 1; } //last page $lastPage = ceil($foundnum/$display); //limit in the query thing $limitQ = 'LIMIT ' .($currentPage - 1) * $display .',' .$display; //normal query and print results $construct = "SELECT * FROM Stacks $limitQ"; $run = mysql_query($construct); //here you do your loop like while($row=@mysql_fetch_object($run)) { print "$row->FieldName"; } //pagination navigation (links) //previous if ($currentPage == 1) { print "Prev "; } else { print "<a href=search.php?page=1>First page</a> "; $previousPage = $currentPage-1; print "<a href=search.php?page=$previousPage>Previous</a>"; } print " { Page $currentPage of $lastPage } "; //for next pages links if ($currentPage== $lastPage) { print "Next last"; } else { $nextPage = $currentPage+1; print " <a href=search.php?page=$nextPage>NEXT</a> "; print " <a href=search.php?page=$lastPage>LAST</a> "; } ?> i get these errors Warning: mysql_query() [function.mysql-query]: Access denied for user 'ustackc1'@'localhost' (using password: NO) in /home/ustackc1/public_html/search.php on line 96 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/ustackc1/public_html/search.php on line 96 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ustackc1/public_html/search.php on line 97 Warning: mysql_query() [function.mysql-query]: Access denied for user 'ustackc1'@'localhost' (using password: NO) in /home/ustackc1/public_html/search.php on line 116 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/ustackc1/public_html/search.php on line 116 First page Previous { Page 2 of 0 } NEXT LAST It shows results are found but doesn't display the results on the page? and when i click on next page then i get those error messages? Quote Link to comment https://forums.phpfreaks.com/topic/170072-pagination-not-working/ Share on other sites More sharing options...
ignace Posted August 13, 2009 Share Posted August 13, 2009 You are using the wrong credentials for your db server Quote Link to comment https://forums.phpfreaks.com/topic/170072-pagination-not-working/#findComment-897185 Share on other sites More sharing options...
MDanz Posted August 13, 2009 Author Share Posted August 13, 2009 can you expand on that? i typed in the correct database, username and password... Quote Link to comment https://forums.phpfreaks.com/topic/170072-pagination-not-working/#findComment-897190 Share on other sites More sharing options...
.josh Posted August 13, 2009 Share Posted August 13, 2009 well you obviously did not, as the error message clearly states as much Quote Link to comment https://forums.phpfreaks.com/topic/170072-pagination-not-working/#findComment-897234 Share on other sites More sharing options...
MDanz Posted August 13, 2009 Author Share Posted August 13, 2009 ok i've changed some stuff around i have it sort of working.. now the pagination is aware of the number of my results... but it doesn't put the appropriate amount on page on. It just lists all of them and says next page? when i click on next page then i get the errors again. you can see here.. http://www.u-stack.com/search.php?search=basketball+video&submit=search i put in the code to display 5 per page? // Number of results per page $display = 5; if(isset($_GET['page'])) { $currentPage = $_GET['page']; } else{ $currentPage = 1; } //last page $lastPage = ceil($foundnum/$display); //limit in the query thing $limitQ = 'type' .($currentPage - 1) * $display .',' .$display; //normal query and print results $construct = "SELECT * FROM Stacks $limitQ"; $run = mysql_query($construct); //here you do your loop like while($row=@mysql_fetch_object($run)) { print "$row->FieldName"; } //pagination navigation (links) //previous if ($currentPage == 1) { print "<font color=white>Prev </font>"; } else { print "<font color=white><a href=search.php?page=1>First page</a></font> "; $previousPage = $currentPage-1; print "<font color=white><a href=search.php?page=$previousPage>Previous</a></font>"; } print " {<font color=white> Page $currentPage of $lastPage </font>} "; //for next pages links if ($currentPage== $lastPage) { print "<font color=white>Next last </font>"; } else { $nextPage = $currentPage+1; print " <font color=white><a href=search.php?page=$nextPage>NEXT</a></font> "; print " <font color=white><a href=search.php?page=$lastPage>LAST</a></font> "; } Quote Link to comment https://forums.phpfreaks.com/topic/170072-pagination-not-working/#findComment-897237 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.