Hey all,

Ive developed a site at www.forwardestates.co.uk but im having a major problem adding some functionality to the search script.

I would like to add a feature whereby users do not have to select a certain option from each of the drop down menus. i.e. I wish to add a 'any property type', 'any number of rooms' etc to each of the drop down menus.

For an example please view the search form at www.theartlounge.com. (browse art)... this is the functionality im after. Here users do not have to select a specific colour.

Really need help with this one guys, been at it for days now and I cant find anything on the net that shows how to do this. Thanks.

Ive included my search script, it may help.

    hello baljeetsall

    couldn't you just take out the number or rooms type of property from your sql statement?

    ie

    <select name="property">
    <option>*</option>Any property
    <option>flat</option>Flat
    </select>

    php

    if($POST['property'] = "")
    {
    $sql = "select
    from table";
    } else {
    $sql = "select * from table where property = " . $
    POST['property'];
    }

    so it selects on all properties in this example

      If you want to have multiple form elements to build up your querystring, this might be a little easier to do:

      Property Type:
      <select name="type">
      <option value="all">Any property</option>
      <option value="flat">flat</option>
      <option value="house">house</option>
      </select>
      <br><br>
      Number Bedrooms:
      <select name="bedrooms">
      <option value="all">Any Number</option>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5+">5+</option>
      </select>
      <br><br>
      Price:
      <select name="price">
      <option value="all">Any Price</option>
      <option value="upto50">up to 50k</option>
      <option value="50-80">50 - 80k</option>
      <option value="80-100">80 - 100k</option>
      <option value="over100">over 100k</option>
      </select>

      <?php

      $sql = "select * from selling,areas,types where (selling_area = areas_id AND selling_type = types_id) ";

      // property type selector
      if($POST['type'] != "all") {
      $sql = $sql + " and types_name = " . $
      POST['type'];
      }

      // num bedrooms selector
      if($POST['bedrooms'] != "all") {
      if ( $
      POST['bedrooms'] == "5+"){
      $sql = $sql + " and selling_rooms >= 5 ";
      } else {
      $sql = $sql + " and selling_rooms= " . $_POST['bedrooms'];
      }
      }

      // price bracket selector
      if($POST['price'] == "upto50") $sql = $sql + " and selling_price <= 50000 ";
      if($
      POST['price'] == "50-80") $sql = $sql + " and (selling_price >= 50000 and selling_price <=80000 )";
      if($POST['price'] == "80-100") $sql = $sql + " and (selling_price >= 80000 and selling_price <=100000 )";
      if($
      POST['price'] == "over100") $sql = $sql + " and selling_price >= 100000 ";

      ?>

      That should sort you out matey.

      Myke.

        5 months later

        I'm trying to follow your example for a database that displays GPS routes.

        The query works fine as long as I have "ALL" selected, but if I try to search using the other parameters I get an error

        Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /foobar/public_html/staticfiles/limitbyquery2.php on line 36
        <form name="form_route_selection" method="post" action="">
          Route Type 
          <select name="routetype" id="routetype">
            <option value="All">All</option>
        	<option value="Circular">Circular</option>
            <option value="Point To Point">Point To Point</option>
          </select>
          <input name="search" type="submit" id="search" value="search">
        </form>
        
        
        <?php
        // Waterloo Station UK =  51.50468231156 , -0.11265277862548828
        $limit = 10;
        $latitudeinput = 51.5046;
        $longitudeinput = -0.1126;
        
        $sql = mysql_query("SELECT * , 6371.04 * acos( cos( pi( ) /2 - radians( 90 - latitudestart ) ) *
        cos( pi( ) /2 - radians( 90 - $latitudeinput ) ) * cos( radians(
        `longitudestart` ) - radians( $longitudeinput ) )  + sin( pi( ) /2 - radians(
        90 - latitudestart ) ) * sin( pi( ) /2 - radians( 90 - $latitudeinput ) ) ) AS
        distancefrompoint
        FROM jos_downloads_files
        ORDER BY distancefrompoint
        LIMIT $limit") or die (mysql_error());
        
        // Route type selector
        if($_POST['routetype'] != "All"){
        $sql = $sql + " and routetype = " . $_POST['routetype'];
        }
        
        while($row=mysql_fetch_array($sql)){
        
        echo " - ". ($row[routelengthmiles])." Miles -  ". number_format($row[distancefrompoint],1)." Miles Away.<br />";
        }
         ?>
        
         

        Am I doing anything silly?

        Cheers, Simon

          Write a Reply...