php three dropdown filter
<p>I have a table called classifieds and it contains the following:</p>

<ul>
<li>id </li>
<li>title</li>
<li>description</li>
<li>state_id</li>
<li>city_id</li>
<li>cat_id</li>
</ul>

<p>This is dynamically populated from database.</p>

<pre><code>&lt;form name="theForm" method="post" action="advanced_search.php"&gt;
    &lt;input type="submit" name="Submit" value="Search" /&gt;
    &lt;select name="categories" &gt;
        &lt;option value=""&gt; Select Category&lt;/option&gt;
    &lt;/select&gt;
    &lt;select name="state" &gt;
        &lt;option value=""&gt; Select state&lt;/option&gt;
    &lt;/select&gt;
    &lt;select name="city" &gt;
        &lt;option value=""&gt; Select city&lt;/option&gt;
    &lt;/select&gt;
    ...
</code></pre>

<p>When I select a category and click search, the result for that category will show up.  If I select a category and a state then I want it to filter to a specified category and state.  The same should occur if a city is selected.</p>

<p>EX: If I select employment category in Minneapolis city, then the search should be filtered to all employments in that city.</p>

<p>With the code bellow it requires to select all the dropdowns to get the filter working. 
What if I want to show all results of a category in a specified state?  What if I want to filter by category only?</p>

<pre><code>if (isset($_POST['Submit'])) {
    $state = $_POST['state'];
    $city = $_POST['city'];
    $categories = $_POST['categories'];

    $select = "SELECT * FROM classifieds";
    $where = " WHERE ( authorized = '1')";

    $where .= " AND (cat = '" . $categories . "' AND state_id = '" . $state . "' AND city_id = '" . $city . "')";

    $where .= " AND (state_id = '" . $state . "' )";
    $where .= " AND (city_id = '" . $city . "' )";
    $q = $select . $where . ' ORDER BY date DESC';
</code></pre>

<p>Can someone walk me through this?</p>
