Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old December 9th, 2003, 03:35 PM
localhost localhost is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Atlanta
Posts: 66 localhost User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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!

Reply With Quote
  #2  
Old December 9th, 2003, 04:09 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
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.

Reply With Quote
  #3  
Old December 9th, 2003, 04:41 PM
localhost localhost is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Atlanta
Posts: 66 localhost User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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!

Reply With Quote
  #4  
Old December 9th, 2003, 05:10 PM
tkarkkainen's Avatar
tkarkkainen tkarkkainen is offline
Moderator
Click here for more information
 
Join Date: Apr 2007
Location: Finland
Posts: 2,326 tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 15677 Folding Title: Novice Folder
Time spent in forums: 6 Days 9 h 32 m 40 sec
Reputation Power: 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'"

Reply With Quote
  #5  
Old December 9th, 2003, 06:23 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
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...


Reply With Quote
  #6  
Old December 10th, 2003, 01:08 PM
localhost localhost is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Atlanta
Posts: 66 localhost User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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.

Reply With Quote
  #7  
Old December 10th, 2003, 02:25 PM
coderboi coderboi is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 80 coderboi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Stuck on Search string

Have a look at number_format() in the PHP manual - that'll do what you need it to

Reply With Quote
  #8  
Old December 10th, 2003, 02:39 PM
localhost localhost is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Atlanta
Posts: 66 localhost User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Stuck on Search string

Thanks I will do that.

/local

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Stuck on Search string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway