Jump to content

Archived

This topic is now archived and is closed to further replies.

genista

Multiple selection criteria

Recommended Posts

Hi I have a form that allows a user to search for suppliers in a given area, at the moment it searches on the supplier that lives in a county, but I have now given the supplier to fill in 3 other counties that they actually cover.

Now I need to update the following query to reflect the 3 new fields: area_covered1, area_covered2, area_covered3:

[code=php:0]
$query = "select county, area_covered1, area_covered2, area_covered3, supplierid, username from suppliers where county =\"$county\" order by username";
[/code]

Any ideas?

Thanks,

G

Share this post


Link to post
Share on other sites
well at face value, i don't see the problem. it looks like it should do what you have said you want it to do. So what is the problem? Also, seeing as how you are selecting all of those fields, if those are all the fields in your table, or if you have maybe one or two more fields that you don't need, I would personally just do this instead:

[code=php:0]
$query = "select * from suppliers where county ='$county' order by username";
[/code]

perhaps you should explain what it is doing wrong. Is it not selecting the stuff, when you know it's in there? Are you getting some kind of error message? A good place to start would be to echo your $query so you can see what is actually being sent to your database.  For instance, it helps you to see if $county is holding the data you expect it to be holding. 

Share this post


Link to post
Share on other sites
Ah sprry, its not that I have an error its the fact that I need to do something like this:

$query = "select * from suppliers where county='$county' or area_covered1 = '$county.'

As you can see at the moment I am only searching the county, I need to search across 3 other fields, but I am troubled as to how I can get this without making it conditional that all 4 fields have the data in to return any results, does that make sense?

Share this post


Link to post
Share on other sites
You'll have to build your WHERE clause on-the-fly.

Share this post


Link to post
Share on other sites
okay on-the-fly then, what does your form look like? are these counties entered in from 3 text fields? dropdowns? checkboxes?

Share this post


Link to post
Share on other sites

×

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.