|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Stuck on Search string
Hi all. I am coding a realtor database. All complete except the search feature. I am trying to give the user the following search options. BTW I am using PHP and Mysql.
Db fields I need to query; city price bedrooms square_feet Form fields in form; city min_price max_price bedrooms square_feet The query I need would be something like this in English. select * from $dbtable WHERE city='$city' and price more than '$min_price' AND price less than '$price' AND bedrooms LIKE "$bedrooms' "; Any help would be very much appreciated! |
|
#2
|
|||
|
|||
|
RE: Stuck on Search string
you pretty much answered your own question. I would write it like so...
select * from $dbtable WHERE city='$city' and price >='$min_price' AND price <='$price' AND bedrooms = '$bedrooms' 1. This should return everything from the table where the city is an identical match. 2. The price is greater than or equal to the minimum price selected. 3. The price is less th or equal to the price selected. 4. and bedrooms is an exact match for how many bedrooms selected. Hope that helps. |
|
#3
|
|||
|
|||
|
RE: Stuck on Search string
Blindeddie,
Thanks that did the trick I think! I had to make 1 minor modification to the query; select * from $dbtable WHERE city='$city' and price >='$min_price' AND price <='$price' AND bedrooms = '$bedrooms' changed: price <='$price' TO price <='$max_price' Now I just need to do further testing to make sure but she seemed to pull the correct results the couple of time I tried it. Perhaps you could help with this one to! What if I added the value "any" to the city dropdown box. Is it possible to do the same search just this time look at all city's with the other matching values? It would make a broader search for the client. Thanks! |
|
#4
|
||||
|
||||
|
RE: Stuck on Search string
It would require you to do this:
1. Your search script checks if "any" is selected 2. If not, do the query blindeddie gave you. 3. If it is, do the same query but leave out the part "city='$city'" |
|
#5
|
|||
|
|||
|
RE: Stuck on Search string
tkarkkainen's suggestion is the way to go... use an if statement to determine the value of the $city variable and if the value is "any", run this query...
select * from $dbtable WHERE price >='$min_price' AND price <='$max_price' AND bedrooms = '$bedrooms' that should do it... |
|
#6
|
|||
|
|||
|
RE: Stuck on Search string
Blindeddie and tkarkkainen,
Thanks. The select statement is working just fine as well as is the query. I might if possible trouble you for one more question. - I need to convert 200000 to $200,000.00 where 20000 is being posted from a form field. and - I need to convert 200000 to $200,000.00 where 20000 is being pulled from a db field. I am sure both are the same answer most likely. Thank you very much for the assistance. |
|
#7
|
|||
|
|||
|
RE: Stuck on Search string
Have a look at number_format() in the PHP manual - that'll do what you need it to
|
|
#8
|
|||
|
|||
|
RE: Stuck on Search string
Thanks I will do that.
/local |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Stuck on Search string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|