kinaski Posted February 20, 2008 Share Posted February 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
revraz Posted February 20, 2008 Share Posted February 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
kinaski Posted February 20, 2008 Author Share Posted February 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
revraz Posted February 20, 2008 Share Posted February 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
kinaski Posted February 20, 2008 Author Share Posted February 20, 2008 Thanks again! Off I go now to try this Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.