Re: [PHP] finding next and prev record in mysql
On Thu, May 10, 2007 11:54 pm, 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 You really really shouldn't be using an ID field for any kind of order involving next/prev... It's just a Bad Idea from the get-go... An ID is supposed to be more abstract than that, really. That said, the IDs in MOST dbs *are* in order, and you *can* just write a query using the result from the one you already have with and get the previous, and another query with to get the next. Limit 1 on both queries. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] finding next and prev record in mysql
-Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Thursday, May 10, 2007 10:09 PM To: Richard Kurth Cc: php-general@lists.php.net Subject: Re: [PHP] finding next and prev record in mysql 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 Ask the mysql list: http://lists.mysql.com/ I'm sure they have been asked a similar thing many times in the past. I did but have not received any awes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] finding next and prev record in mysql
-Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Thursday, May 10, 2007 10:09 PM To: Richard Kurth Cc: php-general@lists.php.net Subject: Re: [PHP] finding next and prev record in mysql 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 Ask the mysql list: http://lists.mysql.com/ I'm sure they have been asked a similar thing many times in the past. I did but have not received any reply at all -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] finding next and prev record in mysql
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
Re: [PHP] finding next and prev record in mysql
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 Ask the mysql list: http://lists.mysql.com/ I'm sure they have been asked a similar thing many times in the past. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php