GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 23-Jul-2003, 18:49
rico rico is offline
New Member
 
Join Date: Jul 2003
Posts: 3
rico is an unknown quantity at this point

Wrapping a query for the next item


I have a database with a set of images in it. Each image has an ID number as well as a category and sub_category field. When a user clicks "next image" I want the db to select the next image in that category and sub_category. The code I have works until i am at the first of last image in the category or sub_category. then it returns null for both of the id's I return. here is my query:

SELECT min( p1.id ) , min( p2.id )
FROM pictures AS p1, pictures AS p2
WHERE p1.id > 46 AND p1.sub_cat = '1' AND p2.sub_cat = '1';


after this, I determine if min(p1.id) is null, then use min(p2.id) as the id. So it takes the smallest id after 46, or the smallest id in the column (with the appropriate cat & sub_cat values). This, however, returns 2 nulls. when i remove the cat & sub_cat limitations, it works fine. any ideas?
  #2  
Old 24-Jul-2003, 07:17
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
Hi rico, welcome to GIDForums

Sorry no-one has got to your question yet, we'll see if someone can figure out your problem.

Rob
  #3  
Old 24-Jul-2003, 07:27
rico rico is offline
New Member
 
Join Date: Jul 2003
Posts: 3
rico is an unknown quantity at this point
Hey, it's no problem -- I work today and tonight and can't get to it until much later. Maybe if I clarify what I'm looking for, it'll be easier:

I want to return to picture Id numbers
(1) the smallest id, greater than the current one that has the same cat and sub_cat
(2) the smallest id overall that has the same cat and sub_cat.


i do this so that when i reach the last pic in that category, it wraps to the first.


thanks.
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search Engine Positioning 101 and 201 "How To" Tips... 000 Search Engine Optimization Forum 0 29-May-2003 10:34

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:57.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.