search form with select and option values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: search form with select and option values

Post by Celauran »

You need something to tie the clauses together. Currently, you've got something like

Code: Select all

SELECT * FROM privatelistings WHERE make LIKE '%Acura%' OR model LIKE '%ILX%' Price BETWEEN 10.00 AND 20.00
whereas you want something like

Code: Select all

SELECT * FROM privatelistings WHERE (make LIKE '%Acura%' OR model LIKE '%ILX%') AND Price BETWEEN 10.00 AND 20.00
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: search form with select and option values

Post by Celauran »

You're appending $price to your query before having defined it.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: search form with select and option values

Post by Celauran »

Code: Select all

  case 1  :  $price = " Price BETWEEN £10 AND £20 ";  break; 
What's going on here? How is price stored in your DB?

Code: Select all

AND price
That's not going to work. 'price' is a string literal.

What is the value of $query after you submit the form?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: search form with select and option values

Post by Celauran »

The fact that you have a hanging AND is going to cause problems for sure. I'd also advise against storing the prices that way; numeric values is a better idea and you can prepend the currency symbol on output. The way you've got things structured is also potentially problematic; your query is only defined if $where_clause contains values, which is fine, but you're trying to execute the query regardless. Finally, what happens if price isn't defined?
Post Reply