From: Mogens Melander Date: May 11 2007 4:20pm Subject: Re: finding next and prev record in mysql List-Archive: http://lists.mysql.com/mysql/206728 Message-Id: <4846.90.184.17.152.1178900428.squirrel@mail.fumlersoft.dk> MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit 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; -- Later Mogens Melander +45 40 85 71 38 +66 870 133 224 -- This message has been scanned for viruses and dangerous content by OpenProtect(http://www.openprotect.com), and is believed to be clean.