Get Next Value

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 :(

Get Next Value

Post by blacksnday »

If I wanted to select a value, then based on that value find the next
available value, how would that be done?

Code: Select all

$query = "select * from table where did='$value' ";
so I first get the value... now based on this I need to
get the next available within the same while
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Give an example of what you are trying to achieve.
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post by blacksnday »

anjanesh wrote:Give an example of what you are trying to achieve.
hmm, i thought i did ...

lets say i grab results with using articleid as
how I identify it. When on the current articleid
I need to display the next available articleid.

If articleid was an auto_increment then it would be easy
as I would just do something like

Code: Select all

$current_article = $row['articleid'];
$next_value = $current_article + 1;
but when it is not auto_inc, and i need to get
the correct id (not just +1) of the next available
I am lost with how to do it.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Do a second mysql_fetch_array(), mysql_fetch_assoc() or mysql_fetch_row() to get the next value and then mysql_data_seek() to a specified location.
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post by blacksnday »

thanks :)
Post Reply