Page 1 of 1

Find/Display Current/Next Number

Posted: Mon Nov 07, 2005 10:44 am
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 :)

Posted: Mon Nov 07, 2005 4:04 pm
by John Cartwright
look up the LIMIT clause, in combination with the ORDER BY clause

Posted: Mon Nov 07, 2005 4:07 pm
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