Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Posts
    4

    Unanswered: 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.

  2. #2
    Join Date
    Feb 2004
    Posts
    533
    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

  3. #3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •