Find/Display Current/Next Number

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Find/Display Current/Next Number

Post by blacksnday »

I have been trying to create a query that will do two things.

First, it checks against $_GET to select and display the proper
number being requested.

Second(the part I cant figure out) it needs to use the current $_GET
value, then check against the current available numbers, then select
and display the next number available... that is closet to the current number.

Example would be:

I am on 10,
The next number is 11.....
sql correctly selects and gets 11 for me.

After 11, the next number is 14.
I need sql to realize next is not in sequence, but still choose the next
number above 11, and display it.

I was thinking about just changing the SELECT
SELECT * FROM table WHERE id =1
so that it first selects the number, then finds and selects the next highest number.

Can this be done?
btw.... this is not being used as auto-inc field...
if so, then there would be no prob :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

look up the LIMIT clause, in combination with the ORDER BY clause
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post by blacksnday »

Ahh yea...
I got that figured out now by doing something like

Code: Select all

mysql_query ("SELECT * FROM ".$prefix."_news WHERE published = '1' ORDER BY DID ASC LIMIT $prevlink,1");
that brings a new set of problems that I updated in my original post at
viewtopic.php?t=39223
Post Reply