Jump to content

Nothing too complicated I guess...HELP!


Penders

Recommended Posts

Hi!

 

I`m trying to make a photo gallery website. I`m trying to echo galleries and images that are only to specific user_id, (SESSION user_id)

 

I found this query and I can`t figure out how to connect it with user_id. Please help!

 

 

$query=" select distinct(images.gal_id),img_name, gname,img_id  from images,  gallery where images.gal_id=gallery.gal_id group by images.gal_id order by gal_id desc limit $eu,$limit";
 
$query2=" select distinct(images.gal_id),img_name, gname,img_id  from images,  gallery where images.gal_id=gallery.gal_id group by images.gal_id order by gal_id ";
 
 
 
Thank You!
Link to comment
https://forums.phpfreaks.com/topic/294754-nothing-too-complicated-i-guesshelp/
Share on other sites

DISTINCT is not a function - it applies to the whole row and not a single field. It is also redundant when using GROUP BY.

 

If you don't know how the images relate to users, how the hell do you expect us to know when we don't even know what your data looks like?

Could be because galI_id in the ORDER BY is ambiguous and I put the WHERE after ORDER (Ooops!)

Try

SELECT 
    gallery.gal_id
    , gname
    , img_id  
    , img_name
FROM 
    gallery
INNER JOIN
    images ON images.gal_id=gallery.gal_id 
WHERE gallery.user_id = $whatever 
ORDER BY gallery.gal_id DESC
LIMIT $eu,$limit

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.