Retrieving the row value of a record with a specfic ID in the results from a query

The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

A web page (weblog.php) contains a listing of a blog entries (from newest to oldest) from a specific user. The URL variable, 'id', defines which user's blogs we are viewing.

Only up to 50 entries will be displayed at once. The URL variable, 'page_number', defines which 50 are shown. The most recent 50 would be on page_number 1, the next most recent 50 would be on page_number 2, etc.

I allow users the ability to edit their blog entries. When a user submits the edited entry, I want them to be redirected back to weblog.php so they can view what they just edited. The problem is that I don't know how to program the script to define the correct 'page_number'.

For example: User '4' decides to edit their 112th most recent blog entry. The script should redirect them back to: "weblog.php?user_id=4&page_number=3."

Its a rather simple concept, but hard to explain. Basically I just want a script to figure out which page a record with a particular ID is on if each page contains 50 records.

Does MySQL have a function that would round up the page_number, like PHP's ceil() function?

you know, that's a really good question

yes, mysql has the CEIL() function, but i didn't use it, i added 1 to the integer dividend instead

of course, you have to be comfortable with integer arithmetic... for example, if the user's page is 37th in sequence, then there are 36 rows with a later timestamp, so 36/50 using integer arithmetic gives 0, and then i just add 1, giving page 1

CEIL(x) returns "the smallest integer value not less than x" and i always have to stop and think (which annoys me) before deciding how to use it

Putting such volatile state info in a session will get you into trouble when the user opens a second browser window and starts editing with both. Not that it would be disasterous here, but may confuse the user. Same with putting this in the query string. By the time they submit window#2, they may have submitted #1 too and now the state info in #2 is invalid and will show incorrect results.

Querying the db, which holds the most current state info, will always return as expected, in this circumstance at least.