therelelogo Posted October 17, 2011 Share Posted October 17, 2011 hi, i'm wondering, is it possible to search by multiple fields at the same time let me re-phrase that, i know it is possible BUT (and i dont know the correct terminology here) can i search by something in the URL too? here is my code: $result = mysql_query("SELECT * FROM adverts WHERE (ad_type = 'standard') AND (category = '$_GET[cat]') AND (i_condition = '$_GET[cond]') ORDER BY item_id DESC") or die(mysql_error()); this page returns all that meet the critera of "category" and "i_condition" BUT if one is returned as null, i.e '' then any from the table that arent null are not returned. i hope i have explained this easy to understand. basically what i want to know is, if a value in the url is null (meaning nothing for that field should be searched for) how can i have it return all the results for the other url search fields? oh god i hope this makes sense. another example: /category_pages/full_cat.php?cat=entertainment /category_pages/full_cat.php?cat=entertainment&cond=new in the first link "cond" is not being searched for so i would want all fields returned that just have the matching "cat" in the second i would want to filter by both, so my question is, in the first example how can i set the code (php above) to just ignore it for the time being unless the "cond" part is in the url? any help appreciated thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted October 17, 2011 Share Posted October 17, 2011 You have to build your where clause dynamically. Quote Link to comment Share on other sites More sharing options...
therelelogo Posted October 18, 2011 Author Share Posted October 18, 2011 any suggestions how to change it? or could point me in the right direction? Quote Link to comment Share on other sites More sharing options...
fenway Posted October 18, 2011 Share Posted October 18, 2011 If you are well-versed in php, a simple if/else will do. Quote Link to comment Share on other sites More sharing options...
therelelogo Posted October 19, 2011 Author Share Posted October 19, 2011 hmm i'm not sure it would to be honest, may be easier to ask then is there a wilcard that would return all values whether the row was blank or had something in it? like * = searches for all? or ALL or something like that? or is that just wishful thinking? Quote Link to comment Share on other sites More sharing options...
fenway Posted October 19, 2011 Share Posted October 19, 2011 That will work, but it's the wrong approach. Don't have mysql do more work to make your life easier. Quote Link to comment 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.