Jump to content

Recommended Posts

  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?

 

Link to comment
https://forums.phpfreaks.com/topic/170072-pagination-not-working/
Share on other sites

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> ";
}

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.