Jump to content


Photo

Multiple selection criteria


  • Please log in to reply
4 replies to this topic

#1 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 September 2006 - 12:20 PM

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:

$query = "select county, area_covered1, area_covered2, area_covered3, supplierid, username from suppliers where county =\"$county\" order by username"; 

Any ideas?

Thanks,

G

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 14 September 2006 - 12:29 PM

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:

$query = "select * from suppliers where county ='$county' order by username"; 

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. 
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 September 2006 - 12:33 PM

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?

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 14 September 2006 - 02:57 PM

You'll have to build your WHERE clause on-the-fly.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 14 September 2006 - 06:41 PM

okay on-the-fly then, what does your form look like? are these counties entered in from 3 text fields? dropdowns? checkboxes?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users