Jump to content

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

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.