Mogens Melander wrote:
On Fri, May 11, 2007 07:15, Richard Kurth wrote:
How would I find the next id and the prev id in sql statement like the one
below. The id number is not going to be in order so I can't do a < or >
limit 1 on the search

SELECT id FROM contacts WHERE category = '5' AND subcategory = '1' AND
members_id= '8' ORDER BY lastname

The PHP variant could look like (prev id):

SELECT id FROM contacts
  WHERE category = '5'
    AND subcategory = '1'
    AND members_id= '8'
    AND lastname < $_POST['lastname']
  ORDER BY lastname
  LIMIT 1;

I forgot to say earlier: my article is about finding both next and previous records in a single query. I don't know if this is what you need or not but I assumed it was.

Baron

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to