Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Form option changes SELECT statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-19-04, 08:53
elkiwi elkiwi is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
Form option changes SELECT statement

Hi I have this in a form:

HTML Code:
<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 Code:
$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); 

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-20-04, 12:09
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 525
You could create an array to hold the min max values or use 2 arrays one for min one for max. Then use the 'PRICE' value as the index of the array to retrieve min max. Another thing you may want to try is using a function, then call the function to return min max values. That would clean up your main code module.

PHP Code:
<html>

<?php

if ( !isset($_POST['PRICE']) ) {
$value = -1;
$message "<b>Select a Price from the list</b>";
}else{
$value $_POST['PRICE'];
$message "<b>Min Max Selection</b>";
}
// set 'Any' to 0
if ($value == "Any")
     
$value =  0;
// create a min max array
// you could use 2 arrays on for min one for max
$prices = array (
        array (
            
"price_min"=> 0,
            
"price_max" => 99999999,
        ),
        array (
            
"price_min"=> 0,
            
"price_max" => 500000,
        ),
        array (
            
"price_min"=> 500000,
            
"price_max" => 750000,
        ),
        array (
            
"price_min"=> 750000,
            
"price_max" => 1000000,
        ),
        array (
            
"price_min"=> 1000000,
            
"price_max" => 1800000,
        ),
);

// Retrieve values from the array only if value set
if ( $value >= ) {
$price_min $prices[$value]["price_min"];
$price_max $prices[$value]["price_max"];
$message $message "<br>Min: $price_min,  Max: $price_max";
}

?>

<head>
  <title></title>
</head>

<body>
  <?php echo $message ?>
  <form method="POST" name="PriceSelect" action="?php print $PHP_SELF?>">
  <p>
  <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>
  <input type="submit" name="OK" value="Button">
  </p>
</body>

</html>



.
__________________
~

Bill
Reply With Quote
  #3 (permalink)  
Old 10-20-04, 12:51
elkiwi elkiwi is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
Thanks very much Bill, you've explained exactly what I couldn't get my head around. I'm going see if I can make it work.

Cheers.

elkiwi
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

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