owner Posted January 31, 2010 Share Posted January 31, 2010 I am getting some pages out of a mySQL database, but I am trying to display what page out of totalpages they are on. For example: Page 4 of 5 How would you figure out that it is the 4th page out of 5 and then display what would be on the 4th page? One problem I am running into is that the id's of each page do not go in order so I cannot do totalpages-currentpage to figure out what page I am on. To get the total pages, I am just using: SELECT COUNT(pid) as count FROM Pages WHERE category=%d (%d is replaced by a variable using sprintf() that denotes what category the pages are in. For example, this category could hold 5 pages. ) Thanks in advance! owner Link to comment https://forums.phpfreaks.com/topic/190422-what-page-am-i-on/ Share on other sites More sharing options...
premiso Posted January 31, 2010 Share Posted January 31, 2010 Simple solution: Add a column in your database called, "pageorder" and use that to show what page they are on. Link to comment https://forums.phpfreaks.com/topic/190422-what-page-am-i-on/#findComment-1004478 Share on other sites More sharing options...
owner Posted January 31, 2010 Author Share Posted January 31, 2010 Is there a way to calculate this? It seems like that would be sort of a redundant column when I can just use the date... Could I use the date that it was added, and count the number of rows that are in the same category? Link to comment https://forums.phpfreaks.com/topic/190422-what-page-am-i-on/#findComment-1004479 Share on other sites More sharing options...
ignace Posted January 31, 2010 Share Posted January 31, 2010 No you can't use the date because when you add 2 pages on the same day your screwed Just do as premiso said add a order column and on each new entry use a query liked described below: SELECT max(order) AS max_order FROM pages; INSERT INTO pages (.., order) VALUES (.., $max_order); After you delete a page: SET @page_order = 0; UPDATE pages SET order = @page_order + 1, @page_order = @page_order + 1; Link to comment https://forums.phpfreaks.com/topic/190422-what-page-am-i-on/#findComment-1004536 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.