Penders Posted February 20, 2015 Share Posted February 20, 2015 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! Quote Link to comment https://forums.phpfreaks.com/topic/294754-nothing-too-complicated-i-guesshelp/ Share on other sites More sharing options...
Barand Posted February 20, 2015 Share Posted February 20, 2015 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? Quote Link to comment https://forums.phpfreaks.com/topic/294754-nothing-too-complicated-i-guesshelp/#findComment-1506277 Share on other sites More sharing options...
Penders Posted February 20, 2015 Author Share Posted February 20, 2015 Images - img_id, gal_id, user_id, img_name ..... gallery - gal_id, gname, user_id...... Quote Link to comment https://forums.phpfreaks.com/topic/294754-nothing-too-complicated-i-guesshelp/#findComment-1506278 Share on other sites More sharing options...
Barand Posted February 20, 2015 Share Posted February 20, 2015 SELECT gallery.gal_id , gname , img_id , img_name FROM gallery INNER JOIN images ON images.gal_id=gallery.gal_id ORDER BY gal_id DESC WHERE gallery.user_id = $whatever LIMIT $eu,$limit Quote Link to comment https://forums.phpfreaks.com/topic/294754-nothing-too-complicated-i-guesshelp/#findComment-1506281 Share on other sites More sharing options...
Penders Posted February 22, 2015 Author Share Posted February 22, 2015 It doesn`t work barand It` s always : Call to a member function fetchColumn() on a non-object Quote Link to comment https://forums.phpfreaks.com/topic/294754-nothing-too-complicated-i-guesshelp/#findComment-1506441 Share on other sites More sharing options...
Barand Posted February 22, 2015 Share Posted February 22, 2015 (edited) 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 Edited February 22, 2015 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/294754-nothing-too-complicated-i-guesshelp/#findComment-1506444 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.