jonw118 Posted August 11, 2010 Share Posted August 11, 2010 Hi there - can anyone lend me a little advise as to what I'm doing wrong here. I have this line: $query=mysql_query("SELECT * FROM gallery a JOIN gallery_image b ON a.id = b.gallery_id where gallery_id=$gallery_id"); I am trying to add an order by statement: order by gallery_image.priority So I created: $query=mysql_query("SELECT * FROM gallery a JOIN gallery_image b ON a.id = b.gallery_id where gallery_id=$gallery_id order by gallery_image.priority"); But, I receive the error (even though there is table called "Gallery Image" and a column called "Priority": Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/***/public_html/***/gallery.php on line 5 select: Unknown column 'gallery_image.priority' in 'order clause' Link to comment https://forums.phpfreaks.com/topic/210438-cant-get-order-by-to-work-in-this-string/ Share on other sites More sharing options...
bh Posted August 11, 2010 Share Posted August 11, 2010 Maybe becouse you use an alias... ? $query=mysql_query("SELECT * FROM gallery a JOIN gallery_image b ON a.id = b.gallery_id where gallery_id=$gallery_id order by b.priority"); Link to comment https://forums.phpfreaks.com/topic/210438-cant-get-order-by-to-work-in-this-string/#findComment-1098056 Share on other sites More sharing options...
aeroswat Posted August 11, 2010 Share Posted August 11, 2010 That doesn't seem like good practice to not use the AS keyword Link to comment https://forums.phpfreaks.com/topic/210438-cant-get-order-by-to-work-in-this-string/#findComment-1098059 Share on other sites More sharing options...
TOA Posted August 11, 2010 Share Posted August 11, 2010 Try telling it how to order by -- ASC or DESC Link to comment https://forums.phpfreaks.com/topic/210438-cant-get-order-by-to-work-in-this-string/#findComment-1098080 Share on other sites More sharing options...
aeroswat Posted August 11, 2010 Share Posted August 11, 2010 Try telling it how to order by -- ASC or DESC Won't matter. It defaults to Ascending Link to comment https://forums.phpfreaks.com/topic/210438-cant-get-order-by-to-work-in-this-string/#findComment-1098084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.