MySQL Forums
Forum List  »  PHP

Call one image by distinct id
Posted by: Claudio Reis
Date: October 14, 2009 06:07AM

Hi all,
I looked it from net with no success...
I have the following DB:

storyid fileid
01------ 01
01------ 02
01------ 03
01------ 04*
02------ 01
02------ 02
02------ 03*
03------ -
03------ -
04------ 01*
.
.
.

All I want is the last one image from each *storyid*, in this case I would have tree images (there are much more storyid...):
01------ 04
02------ 03
04------ 01
.
.
.


I tried the following two queries but there´s something wrong

#1) $result = mysql_query("SELECT DISTINCT storyid FROM atx33p_stories_files ORDER BY storyid DESC LIMIT 7"); //I´ll limit the result to seven

#2) $result = mysql_query("SELECT MAX(storyid) FROM atx33p_stories_files GROUP BY storyid DESC LIMIT 7"); //In this case, I read that it is a hack, but I have no success...

Solution number one gave me the correct storyid(s), but it can not call the respective image, so I tried:

#1) $result = mysql_query("SELECT DISTINCT storyid, fileid FROM atx33p_stories_files ORDER BY storyid DESC LIMIT 7"); //I´ll limit the result to seven

But this returned me the following:
01------ 01
01------ 02
01------ 03

Variations of the solutions give me something like that, or error.

Please, can someone help me?
Thanks in advanced!!!!
Claudio (Brazil)

Options: ReplyQuote


Subject
Written By
Posted
Call one image by distinct id
October 14, 2009 06:07AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.