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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.