Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Newbie SQL Question

Newbie SQL Question
Thread Tools
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status: Offline
Reply With Quote
Jul 12, 2005, 03:38 PM
 
I'm trying to form two SQL statements on a detail page that will provide a item_id number that will be added to a URL string passed to that same page for two buttons, NEXT and PREVIOUS. What's tricky is I don't want to go to the previous/next record by the items' numeric ID #, but rather according to their order by artist last name (and subsequently by artist first name and finally by title if there is ambiguity).

So, here's what I came up with but I know it's not quite right yet:

NEXT
Code:
SELECT item_id FROM items LEFT JOIN artists ON items.artist_id = artists.artist_id WHERE $current_artist_last_name > artists.last_name ASC LIMIT 1
PREVIOUS
Code:
SELECT item_id FROM items LEFT JOIN artists ON items.artist_id = artists.artist_id WHERE $current_artist_last_name < artists.last_name ASC LIMIT 1
Am I on the right track here? I know I haven't even included the logic for what happens if the artists' last name is the same and I'm really not sure how to do that.

EDIT: I'm beginning to think I need to form an array of all the records, sort the array as I want it, and then manipulate the pointer to pick the records I want. So it's a bit more involved than just doing the query. Is that closer?
(Last edited by selowitch; Jul 16, 2005 at 10:12 AM. )
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:21 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2