Jump to content

Search form help needed (select price range field)


kinaski

Recommended Posts

Hello!

 

First of all you should know that I'm beginner with php, so perhaps this is fairly easy to accomplish but it's nightmare for me now

 

I have this situation with my website:

- Search form which search through several fields of the products table (like title, color, condition, delivery).

 

I also have the field for the price which at this moment is simple text field in the form, and visitor should enter the price here to search for.

 

What I want to to now is instead this price field in my form to place a list/menu with select fields with values like:

<$50

$50 - $100

$100 -$150

$150 - 200 etc.

You get the idea anyway.

 

How can I accomplish that a form searches through all the values in a price group ie $50, $51, %52, ..... , $100 and return the right results ?

 

I fope I was clear enough and I hope there's someone out there who can point me to the right direction.

 

Thank you

The first thing you should do is change the prices from TEXT to FLOAT (if you use decimals) or INT (if you don't).

 

Then you can do a simple if less than, if greater than compare.

 

Thanks revraz!

 

But obviously I was not very clear in my post. I didn't meant "price is a text field" for the database field. The database field is FLOAT anyway. What I meant was that currently "my form" has a text field for the price which is pretty inconvenient from the usability perspective(they can enter only one specific price). So how can I recreate this field to be a menu/list field with select options for the price ranges? And how can I append this range to the search query?

 

Thanks again

There are a few ways you can do it.

 

You can create a hard coded option list with the range or you can use a data base and populate the option list with a range.

 

Say range 1 = less than 50, just do a mysql query based on < 50

Range 2 is 51 - 100, do a mysql query > 51 AND < 100

 

etc.

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.