Jump to content

What page am I on?


owner

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

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