Jump to content

search by multiple fields


therelelogo

Recommended Posts

hi,

 

i'm wondering, is it possible to search by multiple fields at the same time  :shrug:

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

Link to comment
https://forums.phpfreaks.com/topic/249236-search-by-multiple-fields/
Share on other sites

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?

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.