February 11, 201016 yr Hi All, Wondering if you can quickly help me with the following issue. I'm trying to get the following to work with no avail "SELECT * FROM mg_gallery_tbl WHERE category='$cat_name' AND second ='$cat_name' ORDER BY 'photographer';" Thanks in advance
February 11, 201016 yr Hi All, Wondering if you can quickly help me with the following issue. I'm trying to get the following to work with no avail "SELECT * FROM mg_gallery_tbl WHERE category='$cat_name' AND second ='$cat_name' ORDER BY 'photographer';" Thanks in advance Try this "SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' AND second ='".$cat_name."' ORDER BY photographer ASC"; And also the ; was in the wrong place on your code it should of been after the "
February 11, 201016 yr Some extra information would help What's happening/not happening that shouldn't/should at the moment If you get mysql errors have you echo'd out the query and the mysql_error() to see what problems it shows?
February 11, 201016 yr Author Hi, When a user uploads a photo, they can assign it to more then one category from choices in two drop down boxes. At the moment, the following code works fine in displaying the pictures in one category: ("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' ORDER BY photographer ASC"); But when i try the following code to display pictures which are in more then one category: ("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' AND second ='".$cat_name."' ORDER BY photographer ASC"); No pictures at all display?
February 11, 201016 yr Hi, When a user uploads a photo, they can assign it to more then one category from choices in two drop down boxes. At the moment, the following code works fine in displaying the pictures in one category: ("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' ORDER BY photographer ASC"); But when i try the following code to display pictures which are in more then one category: ("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' AND second ='".$cat_name."' ORDER BY photographer ASC"); No pictures at all display? People on this forum prob need more info to find out the problem.
February 11, 201016 yr People on this forum prob need more info to find out the problem. I second that At a guess (and several assumptions), try this: ("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' OR second ='".$cat_name."' ORDER BY photographer ASC")
February 11, 201016 yr I second that At a guess (and several assumptions), try this: ("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' OR second ='".$cat_name."' ORDER BY photographer ASC") Well actually that would pull ether from the fields category or second and im guessing he wants both to be pulled at the same time from what hes mentioned so far
February 12, 201016 yr Author Well actually that would pull ether from the fields category or second and im guessing he wants both to be pulled at the same time from what hes mentioned so far Thats correct webdesigner93 i want both to be pulled at the same time. category='".$cat_name." (Pictures 1st category is stored) second='".$cat_name." (Pictures 2nd category is stored) Just not sure how to get both at the same time?
February 12, 201016 yr Well actually that would pull ether from the fields category or second and im guessing he wants both to be pulled at the same time from what hes mentioned so far No it wouldn't product | category | second ------------------------------ bone | dog | NULL collar | dog | cat $cat_name = 'dogs'; $cat_name2 = 'cats'; "SELECT * FROM `mg_gallery_tbl` WHERE `category`='$cat_name' OR `second` ='$cat_name2' ORDER BY `photographer` ASC" You'd then need to loop through each result.
February 12, 201016 yr No it wouldn't product | category | second ------------------------------ bone | dog | NULL collar | dog | cat $cat_name = 'dogs'; $cat_name2 = 'cats'; "SELECT * FROM `mg_gallery_tbl` WHERE `category`='$cat_name' OR `second` ='$cat_name2' ORDER BY `photographer` ASC" You'd then need to loop through each result. I thought OR was used to choose from one or the other not both
February 12, 201016 yr I thought OR was used to choose from one or the other not both The OR will return the table row if either category or second = $cat_name. If you use AND then both category and second must = $cat_name to return the row. I'm unclear exactly what you want to achieve.
February 12, 201016 yr SELECT * FROM `mg_gallery_tbl` WHERE '$category' IN(`category`, `second`) ORDER BY `photographer` ASC Like that? If either the category column or second column contain the $category that row will match
May 2, 201016 yr Author Hi All, Sorry it's took me so long to reply, but i have not been doing much website design recently due to a new job. I just wanted to thank everyone for their input and mention that the following code solved my issue ("SELECT * FROM mg_gallery_tbl WHERE category='".$cat_name."' OR second ='".$cat_name."' ORDER BY photographer ASC") Thanks once again
Create an account or sign in to comment