title: PHP MYSQL HTML Search with multiple filters/ fields
body: <p>I have a MySQL database with 5 tables </p>
  
  <pre><code> - companies
   - place
   - category
   - sub-category
   - company-sub-category
  </code></pre>
  
  <hr>
  
  <pre><code>'companies' consist of 6 column:
  
   - company_id (**PK**)
  
   - company name 
  
   - place_id (**FK**)
  
   - address
  
   - cat_id  (**FK**)
  
   - company_subcat_id  (**FK**)
  </code></pre>
  
  <hr>
  
  <pre><code>'place' consist of 2 column:
  
   - place_id (**PK**)
  
   - place_name  (**FK**)
  </code></pre>
  
  <hr>
  
  <pre><code>'category' consist of 2 column:
  
   - cat_id (**PK**)
  
   - cat_name  (**FK**)
  </code></pre>
  
  <hr>
  
  <pre><code>'sub-category' consist of 2 column:
  
   - sub-cat_id(**PK**)
  
   - sub-cat_name  (**FK**)
  </code></pre>
  
  <hr>
  
  <pre><code>'company-sub-category' consist of 3 column:
  
   - company_subcat_id (**PK**)
  
   - company_id   (**FK**)
  
   - sub-cat_id   (**FK**)
  </code></pre>
  
  <hr>
  
  <p>I would like to make a :-</p>
  
  <ol>
  <li><p>Search with using PHP HTML using the database in the MySQL. </p></li>
  <li><p>The search form also has a filtering system like the ones showed in the html below.</p></li>
  <li><p>i would like the results to include the company's name </p></li>
  <li><p>I would also like to make the results appear in another page "search-results.html"</p></li>
  </ol>
  
  <p>I am fairly new to php and am not sure how to go about making the search form work.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!-- Search --&gt;
  
  &lt;nav id="c-menu--slide-top" class="c-menu c-menu--slide-top"&gt;
    &lt;button class="c-menu__close" style="float: right;background: transparent;font-size: 45px;"&gt;
    &lt;strong&gt;x&lt;/strong&gt;&lt;/button&gt;
    &lt;ul class="c-menu__items"&gt;
      &lt;li class="c-menu__item"&gt;
        &lt;form action="" target="search-results.html" method="post" id="nl-form" class="nl-form"&gt;
            I am looking for
            &lt;select name="category" id="category"&gt;
              &lt;option value="0" selected&gt;category choice&lt;/option&gt;
              &lt;option value="1"&gt;Women&lt;/option&gt;
              &lt;option value="2"&gt;Men&lt;/option&gt;
              &lt;option value="3"&gt;Kids&lt;/option&gt;
            &lt;/select&gt;'s
            &lt;br /&gt;
            &lt;select name="sub-category" id="sub-category"&gt;
              &lt;option value="" selected&gt;-sub-category&lt;/option&gt;
              &lt;option value="1"&gt;Jackets&lt;/option&gt;
              &lt;option value="2"&gt;Tops&lt;/option&gt;
              &lt;option value="3"&gt;Bottoms&lt;/option&gt;
              &lt;option value="4"&gt;Accesories&lt;/option&gt;
              &lt;option value="5"&gt;Undergarments&lt;/option&gt;
              &lt;option value="6"&gt;Shoes&lt;/option&gt;
            &lt;/select&gt;
            &lt;br /&gt;around 
            &lt;select name="price_range" id="price_range"&gt;
              &lt;option value="0" selected&gt;price range&lt;/option&gt;
              &lt;option value="$"&gt;$&lt;/option&gt;
              &lt;option value="$$"&gt;$ $&lt;/option&gt;
              &lt;option value="$$$"&gt;$ $ $&lt;/option&gt;
              &lt;option value="$$$$"&gt;$ $ $ $&lt;/option&gt;
            &lt;/select&gt;
            eatery
            &lt;br /&gt; and would prefer
            &lt;select name="pickup_choice" id="pickup_choice"&gt;
              &lt;option value="0" selected&gt;prefered chioce&lt;/option&gt;
              &lt;option value="1"&gt;Home Delivery&lt;/option&gt;
              &lt;option value="2"&gt;Self pick-up&lt;/option&gt;
            &lt;/select&gt;
            &lt;br /&gt;at
             &lt;input type="text" value="" name="place" placeholder="location" data-subline=" eg.&lt;em&gt;little India&lt;/em&gt; or &lt;em&gt;Chinatown&lt;/em&gt;etc"/&gt;
            &lt;div class="nl-submit-wrap"&gt;
              &lt;button class="nl-submit" type="submit"  href="search-result.html" name="submit"&gt;&lt;a href="search-result.html"&gt; Find a store&lt;/a&gt;&lt;/button&gt;
  
  
  
            &lt;/div&gt;
            &lt;div class="nl-overlay"&gt;&lt;/div&gt;
          &lt;/form&gt;
          &lt;script src="js/nlform.js"&gt;&lt;/script&gt;
       &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/nav&gt;
  
  &lt;!--End of Search--&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is the html file I've used, I didnt include the CSS and JS file as I figured would not be necessary, however if anyone would like me to show it, tell me and I'll be more than glad to do it.</p>
  
  <p>Your help is greatly appreciated and i would like to thank you in advance.</p>
  
  <hr>
  
  <p>this is the PHP that i came </p>
  
  <pre><code>    &lt;?php
  
  
          $whereClauses = array(); 
          if (! empty($_POST['category'])) $whereClauses[] ="category='".//**mysql_real_escape_string($_POST['category'])."'";
  
          if (! empty($_POST['sub_category'])) 
            $whereClauses[] ="category='".mysql_real_escape_string($_POST['sub_category'])."'"; 
          $where = ''; 
  
          if (! empty($_POST['price_range'])) 
            $whereClauses[] ="price_range='".mysql_real_escape_string($_POST['price_range'])."'"; 
          $where = ''; 
  
          if (! empty($_POST['pickup_choice'])) 
            $whereClauses[] ="pickup_choice='".mysql_real_escape_string($_POST['pickup_choice'])."'"; 
          $where = ''; 
  
          if (count($whereClauses) &gt; 0) 
          { 
            $where = ' WHERE '.implode(' AND ',$whereClauses); 
          } 
  
          $sql = mysql_query("SELECT * FROM mytable ORDER BY id DESC $limit" .$where);//**  
          $result=mysql_query($sql);
          while ($row = mysql_fetch_assoc($result)) {
          echo $row['cuisine'];
          echo $row['Jobs'];
  
          }
          ?&gt;
  
  &lt;!-- end snippet --&gt;
  </code></pre>
  
  <hr>
  
  <p>and here is the 'search-result.html' page :_</p>
  
  <pre><code><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>    &lt;/head&gt;
          
  
        &lt;body&gt;
      &lt;div class="container"&gt;
          &lt;div class="well well-sm list-grid-toggle"&gt;
              &lt;strong&gt;Category Title&lt;/strong&gt;
              &lt;div class="btn-group"&gt;
                  &lt;a href="#" id="list" class="btn btn-default btn-sm"&gt;&lt;span class="glyphicon glyphicon-th-list"&gt;
                  &lt;/span&gt;List&lt;/a&gt; &lt;a href="#" id="grid" class="btn btn-default btn-sm"&gt;&lt;span
                      class="glyphicon glyphicon-th"&gt;&lt;/span&gt;Grid&lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div id="products" class="row list-group"&gt;
              &lt;div class="item  col-xs-6 col-lg-4"&gt;
                  &lt;div class="thumbnail comany-detail"&gt;
                      &lt;img class="group list-group-image" src="http://placehold.it/400x250/000/fff" alt="" /&gt;
                      &lt;div class="caption"&gt;
                          &lt;h4 class="group inner list-group-item-heading"&gt;
                              Company Name&lt;/h4&gt;
                          &lt;p class="group inner list-group-item-text"&gt;
                              Product description... Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
                              sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.&lt;/p&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-xs-12 col-md-6"&gt;
                                  &lt;p class="lead"&gt;
                                      $$$$&lt;/p&gt;
                              &lt;/div&gt;
                              &lt;div class="col-xs-12 col-md-6 company-link-btn"&gt;
                                  &lt;a class="btn btn-success company-link" href="company-profile.html"&gt;View Menu&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="item  col-xs-6 col-lg-4"&gt;
                  &lt;div class="thumbnail company-detail"&gt;
                      &lt;img class="group list-group-image" src="http://placehold.it/400x250/000/fff" alt="" /&gt;
                      &lt;div class="caption"&gt;
                          &lt;h4 class="group inner list-group-item-heading"&gt;
                              Company Name&lt;/h4&gt;
                          &lt;p class="group inner list-group-item-text"&gt;
                              Product description... Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
                              sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.&lt;/p&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-xs-12 col-md-6"&gt;
                                  &lt;p class="lead"&gt;
                                      $$$$&lt;/p&gt;
                              &lt;/div&gt;
                              &lt;div class="col-xs-12 col-md-6 company-link-btn"&gt;
                                  &lt;a class="btn btn-success company-link" href="company-profile.html"&gt;View Menu&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="item  col-xs-6 col-lg-4"&gt;
                  &lt;div class="thumbnail company-detail"&gt;
                      &lt;img class="group list-group-image" src="http://placehold.it/400x250/000/fff" alt="" /&gt;
                      &lt;div class="caption"&gt;
                          &lt;h4 class="group inner list-group-item-heading"&gt;
                              Company Name&lt;/h4&gt;
                          &lt;p class="group inner list-group-item-text"&gt;
                              Product description... Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
                              sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.&lt;/p&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-xs-12 col-md-6"&gt;
                                  &lt;p class="lead"&gt;
                                      $$$$&lt;/p&gt;
                              &lt;/div&gt;
                              &lt;div class="col-xs-12 col-md-6 company-link-btn"&gt;
                                  &lt;a class="btn btn-success company-link" href="company-profile.html"&gt;View Menu&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="item  col-xs-6 col-lg-4"&gt;
                  &lt;div class="thumbnail restaurant-detail"&gt;
                      &lt;img class="group list-group-image" src="http://placehold.it/400x250/000/fff" alt="" /&gt;
                      &lt;div class="caption"&gt;
                          &lt;h4 class="group inner list-group-item-heading"&gt;
                              Restaurant Name&lt;/h4&gt;
                          &lt;p class="group inner list-group-item-text"&gt;
                              Product description... Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
                              sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.&lt;/p&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-xs-12 col-md-6"&gt;
                                  &lt;p class="lead"&gt;
                                      $$$$&lt;/p&gt;
                              &lt;/div&gt;
                              &lt;div class="col-xs-12 col-md-6 restaurant-link-btn"&gt;
                                  &lt;a class="btn btn-success restaurant-link" href="restaurant-profile.html"&gt;View Menu&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="item  col-xs-6 col-lg-4"&gt;
                  &lt;div class="thumbnail restaurant-detail"&gt;
                      &lt;img class="group list-group-image" src="http://placehold.it/400x250/000/fff" alt="" /&gt;
                      &lt;div class="caption"&gt;
                          &lt;h4 class="group inner list-group-item-heading"&gt;
                              Company Name&lt;/h4&gt;
                          &lt;p class="group inner list-group-item-text"&gt;
                              Product description... Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
                              sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.&lt;/p&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-xs-12 col-md-6"&gt;
                                  &lt;p class="lead"&gt;
                                      $$$$&lt;/p&gt;
                              &lt;/div&gt;
                              &lt;div class="col-xs-12 col-md-6 company-link-btn"&gt;
                                  &lt;a class="btn btn-success company-link" href="restaurant-profile.html"&gt;View product&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="item  col-xs-6 col-lg-4"&gt;
                  &lt;div class="thumbnail company-detail"&gt;
                      &lt;img class="group list-group-image" src="http://placehold.it/400x250/000/fff" alt="" /&gt;
                      &lt;div class="caption"&gt;
                          &lt;h4 class="group inner list-group-item-heading"&gt;
                              Company Name&lt;/h4&gt;
                          &lt;p class="group inner list-group-item-text"&gt;
                              Product description... Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
                              sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.&lt;/p&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-xs-12 col-md-6"&gt;
                                  &lt;p class="lead"&gt;
                                      $$$$&lt;/p&gt;
                              &lt;/div&gt;
                              &lt;div class="col-xs-12 col-md-6 company-link-btn"&gt;
                                  &lt;a class="btn btn-success company-link" href="company-profile.html"&gt;View product&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
      &lt;/div&gt;
  
          &lt;script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'&gt;&lt;/script&gt;
  
          &lt;script src="js/search-result.js"&gt;&lt;/script&gt;
          
          
        &lt;/body&gt;
      &lt;/html&gt;</code></pre>
  </div>
  </div>
  
  </code></pre>