php search box with double dropdown list
<p>Here is the updated code.</p>

<h2>classifieds table</h2>

<h2>id | title | description | state_id | city_id |</h2>

<h2>1   Ford   | ford for sell|  1       |    1</h2>

<p>2 Ford     | ford explorer| 2        |    1</p>

<h2>state table</h2>

<h2>id | name |</h2>

<p>1   Texas
2   Arizona</p>

<p>city table</p>

<hr>

<h2>id   | name      | state_id</h2>

<p>1     Arlington   1
2     Globe       2</p>

<p>The code that does the search and prints the results is all here:</p>

<p>So this file called search.php</p>

<pre><code>enter  &lt;?php
   $conn = mysql_connect('localhost', 'root','');
  $db = mysql_select_db('files',$conn);
  $input = $_GET['query'];
  $state = $_POST['state'];
 $city = $_POST['city'];
 if (isset($input) &amp;&amp; $input != "" ) {
 $select = "SELECT * FROM classifieds";
 $where = " WHERE (title like '%" . $input . "%'  OR description like '%" . $input .   

 "%')";
if (!empty($city)) {
$select .= " LEFT JOIN city ON classifieds.city_id=city.id";
$where .= " AND city.name = '" . $city . "'";
}
if (!empty($state)) {        
$select .= " LEFT JOIN state ON classifieds.state_id=state.id";
$where .= " AND state.name = '" . $state . "'";
}    
$q = $select . $where . ' ORDER BY date DESC';
$r = mysql_query($q);
$rows = mysql_num_rows($r);
}
echo $rows; ?&gt; Search Results For: &lt;?PHP echo $input; 
if ($rows &gt; 0) {
while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
$description = $row['description'];
echo "  &lt;tr  &gt;
&lt;td &gt;&lt;a href='classified-" . $row['adid'] . ".htm' &gt;" . $row['title'] . "&lt;/a&gt;&lt;br /&gt;
 &lt;span&gt;&lt;em&gt;&lt;a href='category-" . $cat . ".php'&gt;" . $catname . "&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;" .    
$description . "...&lt;/span&gt;&lt;/td&gt;
 &lt;/tr&gt;
  ";
  }
   }
  ?&gt;
   &lt;form action="search.php" method="get"&gt;
   &lt;input type="text" name="query" /&gt;
  &lt;input type="submit" name="Submit" value="Search" /&gt;
   &lt;select name="state" &gt;
&lt;option value="null"&gt;&lt;/option&gt;
&lt;?php
//POPULATE DROP DOWN MENU WITH STATES FROM A GIVEN REGION, COUNTRY
$sql = "SELECT id, statename FROM state";
$states = mysql_query($sql,$conn);
while($row = mysql_fetch_array($states))
{
    echo ("&lt;option value=".$row[id]." &gt;$row[statename]&lt;/option&gt;");
}
?&gt;
&lt;/select&gt;
&lt;select name="city" &gt;
&lt;option value="null"&gt;&lt;/option&gt;
&lt;?php
$sql = "SELECT id, city FROM city  ";
$cities = mysql_query($sql,$conn);
while($row = mysql_fetch_array($cities))
{
    echo ("&lt;option value=".$row[id]."&gt;$row[city]&lt;/option&gt;");
}
?&gt;  here
</code></pre>
