Page 1 of 1

how to stop an option value searching mysql

Posted: Thu Feb 12, 2009 8:02 pm
by djjamiegee
hi

am am still very new to mysql and php coding. I am making an estate agent site with a property search feature. i hate it all working how i want it to but now i have thought of another option for them to choose but dont know how to go about it.

Code: Select all

<form action="finderresults.php" method="get">
<table width="608" border="0" cellpadding="1">
  <tr>
    <td width="109"><legend>Type</legend></td>
    <td width="100"><legend>Min. Bedrooms</legend></td>
    <td width="88"><legend>Max. Price</legend></td>
    <td width="120"><legend>Area [eg. basildon]</legend></td>
    <td width="153"><legend></legend></td>
    <td width="12"><legend>&nbsp;</legend></td>
  </tr>
  <tr>
    <td><select name="type" id="select" class="select">
      <option value="no">No pref</option>
      <option value="house">House</option>
      <option value="flat">Flat</option>
      <option value="bungalow">Bungalow</option>
      <option value="mid">Mid Terrace</option>
      <option value="end">End Terrace</option>
      <option value="semi">Semi Detached</option>
      <option value="detached">Detached</option>
      <option value="cottage">Cottage</option>
      <option value="other">Other</option>
      </select></td>
    <td><select name="bedrooms" id="select" class="select">
      <option value="1">1 Bedroom</option>
      <option value="2">2 Bedrooms</option>
      <option value="3">3 Bedrooms</option>
      <option value="4">4 Bedrooms</option>
      <option value="5">5+ Bedrooms</option>
      </select></td>
    <td><select name="maxprice" id="select" class="select">
      <option value="50000">£50,000</option>
      <option value="100000">£100,000</option>
      <option value="150000">£150,000</option>
      <option value="200000">£200,000</option>
      <option value="250000">£250,000</option>
      <option value="300000">£300,000</option>
      <option value="350000">£350,000</option>
      <option value="400000">£400,000</option>
      <option value="450000">£450,000</option>
      <option value="500000">£500,000 +</option>
      </select></td>
    <td><label>
      <input type="text" name="area" id="label" />
    </label></td>
    <td valign="middle"><input name="submit" type="submit"/></td>
    <td>&nbsp;</td>
  </tr>
</table>
as you can see i have 4 'option' drop down boxes and they can choose which options they want and it will search mysql but now i want it to so they can have one box as 'NO Pref' so it will not search that dropdown box but will still use the other 3 dropdown boxes to search my sql. i think i need and if statment but not sure how to code.

Code: Select all

<?php
 
    echo "<table border='0' cellpadding='0' align='center' width='600'>";
  echo "<tr>";
    echo "<td width=100' align='center'></td>";
   echo "<td width='120' align='left'>Address</td>";
   echo  "<td width='60' align='center'>Bedrooms</td>";
    echo  "<td width='60' align='center'>Type</td>";
    echo  "<td width='70' align='center'>Area</td>";
    echo  "<td width='80' align='center'>Price</td>";
    echo  "<td width='80' align='center'></td>";
  echo  "</tr>";
echo  "</table>";
 
$type=$_GET['type'];
$bedrooms=$_GET['bedrooms'];
$maxprice=$_GET['maxprice'];
$area=$_GET['area'];
 
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("mysql14.streamline.net","djjamiegee1","sosolid"); 
    
//select which database you want to edit
mysql_select_db("djjamiegee1"); 
 
//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search  
 
$result = mysql_query("SELECT * from properties WHERE type = '$type' AND bedrooms >= '$bedrooms' AND maxprice < '$maxprice' AND area LIKE '$area' ORDER BY  bedrooms
;");
 
if ( $type == "no" ) {
 
//grab all the content
while($r=mysql_fetch_array($result))
{   
   $type=$r["type"];
   $bedrooms=$r["bedrooms"];
   $maxprice=$r["maxprice"];
   $area=$r["area"];
   $first_address=$r["first_address"];
   $link=$r["link"];
   $image=$r["image"];
   $postcode=$r["postcode"];
 
//display the row
    echo "<table border='0' cellpadding='0' align='center' width='600' class='search'>";
  echo "<tr'>";
    echo "<td width='100'><img src=\"" . $r["image"] .  "\"></td>";
   echo "<td width='120'>$first_address<br>$postcode</td>";
   echo  "<td width='60' align='center'>$bedrooms</td>";
    echo  "<td width='60' align='center'>$type</td>";
    echo  "<td width='70' align='center'>$area</td>";
    echo  "<td width='80' align='center'>£$maxprice</td>";
    echo  "<td width='80' align='center'><a href=\"" . $r["link"] . "\">
<img src=\"info.png" . "\" border=0 alt=\"" . "\">
</a></td>" ;
 
  echo  "</tr>";
echo  "</table>";
echo "<br>";
}
?>
many thanks in advance sorry if i havent explained very well.

jamie

Re: how to stop an option value searching mysql

Posted: Thu Feb 12, 2009 11:08 pm
by josh
if( isset( //someVal ) )
{
array_push( $options_to_filter_by, //someVal );
}

// generate query with a conjunction ( where clause with AND keyword ) of each item in the array.

Re: how to stop an option value searching mysql

Posted: Thu Feb 12, 2009 11:29 pm
by John Cartwright
Posting your database credentials.. AGAIN.
Posting php code without the appropriate tags...AGAIN.

Not to mention we already have an open thread on the subject.

:crazy:

Topic locked.