If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Dynamic Query help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-10-03, 16:57
dobrmen dobrmen is offline
Registered User
 
Join Date: Dec 2003
Posts: 2
Dynamic Query help

I am building a basic search from to query a rental property database. I have created the following query:

$query="select id,add1,add2,city,rent,bedroom from $tbl_prop where
city='$city' and rent <='$rent' and style='$style' and bedroom >= '$bdrm' order by rent";

The problem is that if the user leaves say the rent dropdown blank then I return 0 results instead of all results regardless of the amount of rent.

Any ideas on how I can make this happen?

Thanks
Lou
Reply With Quote
  #2 (permalink)  
Old 12-15-03, 00:29
i4u_dev4 i4u_dev4 is offline
Registered User
 
Join Date: Oct 2003
Posts: 13
Thumbs up try this

use this

$query="select id,add1,add2,city,rent,bedroom from $tbl_prop where
city='$city' ";
if (!empty($rent)){ $query.=" and rent <='$rent' "; }
.....


and so on

__________________
Manish Khanna
manish@i4u.com.au
Reply With Quote
  #3 (permalink)  
Old 12-15-03, 11:24
dobrmen dobrmen is offline
Registered User
 
Join Date: Dec 2003
Posts: 2
Re: try this

BINGO....

Thanks for your help.

Quote:
Originally posted by i4u_dev4
use this

$query="select id,add1,add2,city,rent,bedroom from $tbl_prop where
city='$city' ";
if (!empty($rent)){ $query.=" and rent <='$rent' "; }
.....


and so on

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On