PDA

View Full Version : How do i write this SQL statement??


deafboyzaudio
06-22-2010, 10:15 PM
I have this statement:
"SELECT pics.pic_id, pics.pic_t_filename, pics.pic_caption, ".
"(pic_ratings.total_value/pic_ratings.total_votes) FROM pics".
" LEFT JOIN pic_ratings ON pics.pic_id = pic_ratings.pic_id ".
"ORDER BY (pic_ratings.total_value/pic_ratings.total_votes) DESC LIMIT 10";

Basically it pulls pictures info from one table and sorts those pics according to the rating information gotten from another table at the same time....

It is used for a top rated pictures page.

How do I make this only return results from a specific user?? I have tried numerous ways and cant seem to get it...

edbr
06-23-2010, 03:08 AM
how do you establish the user?
basically though i would use an if condition matching the user id and the relevant field of their images

deafboyzaudio
06-24-2010, 05:24 AM
The username is stored in $username if thats what you mean....

I have a feeling that I cant filter out by the username b/c im not searching for everything (*) but i cant get it to work with a SELECT *

basically though i would use an if condition matching the user id and the relevant field of their images

Are you saying to return all the results and then pull out the ones out of the array that equal that username?

There has to be a way to get the query with SQL from the get go, that way i wont have to fatten it up just to tone it down....

edbr
06-24-2010, 08:28 AM
then use a where condition

deafboyzaudio
06-30-2010, 06:02 AM
that works... i was hung up on using the *... thanks