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 > Database Server Software > MySQL > Drop down form select. Array?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-19-04, 05:13
elkiwi elkiwi is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
Drop down form select. Array?

Hi I have this in a form:

<select name="PRICE" id="PRICE">
<option>Any</option>
<option value="1">0 to 499.000</option>
<option value="2">500.000 to 750.000</option>
<option value="3">750.001 to 1.000.000</option>
<option value="4">1.000.001 to 1.800.000</option>
</select>

and this on a search results page:

[php]
$value = $HTTP_POST_VARS['PRICE'];
if ($value == 1)
{
$price_min = 0;
$price_max = 500000;
}
else if ($value == 2)
{
$price_min = 500000;
$price_max = 750000;
}
else if ($value == 3)
{
$price_min = 750000;
$price_max = 1000000;
}
else if ($value == 4)
{
$price_min = 1000000;
$price_max = 1800000;
}
else {
$price_min = 0;
$price_max = 99999999;
}

$query_summary = sprintf("SELECT PROP_ID, TITLE, PROPTYPE, `REF`, AREA, PRICE, ROOMS, LOC_DSC, ZONE FROM property LEFT JOIN zone ON (property.area = zone.zone_id) WHERE ZONE LIKE '%%%s%%' AND PRICE BETWEEN $price_min AND $price_max", $ColZone_summary);

[php]

I know there's a better way to do it but I'm not sure how.

Any help would be really appreciated.

Thanks

Peter.
Reply With Quote
  #2 (permalink)  
Old 10-19-04, 06:47
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
yes, there's a better way

if the Any option is selected, your script should not use $price_min=0 and
$price_max=99999999, but instead, it should not generate the AND...BETWEEN condition into the query string

i can't give you the code, though, because i don't do php, so if you're not sure how to do that, perhaps ask in the php forum
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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