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

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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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