Re: MySQL previous next query

From: Date: Thu, 08 Feb 2001 08:55:47 +0000
Subject: Re: MySQL previous next query
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-38723@lists.php.net to get a copy of this message
> I need to build a query that needs to find the previous or next record in a > database using a form. The records are numbered using a field called > 'sb_num'. This field is initially set using the form. > Would something like this work > Next: > Select 'field1', 'field2' from table order by sb_num where $sb_num>=++sb_num > limit 1 > > Previous > Select 'field1', 'field2' from table order by sb_num desc where > $sb_num<=--$sb_num limit 1 Yes, only not quite... select ... where sb_num > $sb_num select ... where sb_num < $sb_num Note that it's possible to reach the first or last record, and then there is no "Next" or "Previous". A nice interface would disable the un-usuable link. -- Visit the Zend Store at http://www.zend.com/store/ Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#38723) next »