Hello everyone! I have perhaps little but however "ugly" problem with paginating (MySQL + PHP). So, my paginating script works usually just fine, but there is a bug, that will occur in some situations.
I try to explain. If I set $limit to be 10 (for instance), and I have just those 10 records in my table, then the paginating script generates useless extra link and useless extra page. This additional page is empty but contains those useless links like this 1 2 Next 10. Besides that extra page is shown unnecessary warnings as "nothing to show". And if I have althoug 19 records in the table and I set $limit=19, the paginating script generates links in that way : 1 2 Next 19. If I click that link 2, an useless page will be opened with links and warning.
I have tried to get out of those extra link and page, but I could not to solve the problem. Could someone tell, what I should do, please?
PHP Code:
<? //Connect to the database and some HTML $limit = 10; // how many records is shown on the page //how many rows $query_count ="SELECT id,item FROM items"; $result_count = mysql_query($query_count); //rows total $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } //how many pages is required to paginate
$limitvalue = $page * $limit - ($limit); //Selecting the data to show with LIMIT clause $query = "SELECT id, item, description, image, status FROM items "; $query .= "ORDER BY id DESC LIMIT $limitvalue, $limit ";
$result = mysql_query($query); $num= mysql_num_rows($result); //Generating table with altering colors to show output of the query //Paginating continues here, I assume that the problem is here(?) if($page != 1){ $pageprev = $page-1;
I suggest you check out http://www.phpfreaks.com/tutorials/73/0.php for all your page numbering needs. I used that tutorial to help me with my page numbering and i've never had a drama or any miswanted links. I hope it helps you.
-Peter
__________________
Current Project: GGAC Website
Project Link: http://peter.5gigs.com/
I suggest you check out http://www.phpfreaks.com/tutorials/73/0.php for all your page numbering needs. I used that tutorial to help me with my page numbering and i've never had a drama or any miswanted links. I hope it helps you.
-Peter
Thank for your reply. Yes, this tutorial seems to be just for my problem
I think it can help me to create good-working paginating script.