title: Best way to code PHP/MYSQL search with options
body: <p>So I am building a search form which has a lot of options for users to select from. As you can see from the image below a user selects a search criteria and it allows them to enter or check what they like. If this is unticked it removes all values/unchecks all the boxes.</p>
  
  <p>I originally only had weight/height/gender as the search but since then have added more.</p>
  
  <p>I already coded the weight/height/gender search options and it ended being a lot of if statements checking what was selected/null then creating the appropriate MYSQL queries.</p>
  
  <p>I am not entirely sure how I should go about (if I should start again) with the rest of the options. Is there an easier away around this? I just need some direction so I can make this a bit more effective.</p>
  
  <p>Thanks!</p>
  
  <p><img src="https://i.stack.imgur.com/7MOkC.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/Xi16S.png" alt="enter image description here"></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>require 'functions.php';
   
   //Search data
   //$weight_min = $_POST['weight_min'];
   //$weight_max = $_POST['weight_max'];
   //$height_min = $_POST['height_min']; 
   //$height_max = $_POST['height_max'];
   //$gender_select = $_POST['gender_select'];
   
   if("" == trim($_POST['weight_min'])){
       $weight_min = '';
   }
   else
   {
    $weight_min = $_POST['weight_min'];
   }
   
   if("" == trim($_POST['weight_max'])){
       $weight_max = '';
   }
   else
   {
    $weight_max = $_POST['weight_max'];
   }
   
   if("" == trim($_POST['height_min'])){
       $height_min = '';
   }
   else
   {
    $height_min = $_POST['height_min'];
   }
   
   if("" == trim($_POST['height_max'])){
       $height_max = '';
   }
   else
   {
    $height_max = $_POST['height_max'];
   }
   
   if (!isset($_POST['gender_select'])){
       
    $gender_select = '';
   }
   else
   {
    $gender_select = $_POST['gender_select'];
   }
   
   //Show test 
   //echo "sent: weight-min: " .$weight_min. " weight-max: " .$weight_max. " height-min: ".$height_min." height-max: ".$height_max." gender-select: ".$gender_select."&lt;p&gt;";
   
   check_null_values($weight_min, $weight_max, $height_min, $height_max, $gender_select);
   </code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> function check_null_values($weight_min, $weight_max, $height_min, $height_max, $gender_select)
   {
    //Weight
    if($weight_min !=null &amp;&amp; $weight_max != null &amp;&amp; $height_min == null &amp;&amp; $height_max == null &amp;&amp; $gender_select == null)
    {
     select_weight($weight_min, $weight_max);
     //echo "select_weight";
    }
    //Height
    else if($weight_min == null &amp;&amp; $weight_max == null &amp;&amp; $height_min != null &amp;&amp; $height_max != null &amp;&amp; $gender_select == null)
    {
     select_height($height_min, $height_max);
     //echo "select_height";
    } 
    //Gender
    else if($weight_min == null &amp;&amp; $weight_max == null &amp;&amp; $height_min == null &amp;&amp; $height_max == null &amp;&amp; $gender_select != null)
    {
     select_gender($gender_select);
     //echo "select_gender";
    }
    //Weight + Height
    else if($weight_min != null &amp;&amp; $weight_max != null &amp;&amp; $height_min != null &amp;&amp; $height_max != null &amp;&amp; $gender_select == null)
    {
     select_weight_height($weight_min, $weight_max, $height_min, $height_max);
     //echo "select_weight_height";
    }
    //Weight + Gender
    else if($weight_min != null &amp;&amp; $weight_max != null &amp;&amp; $height_min == null &amp;&amp; $height_max == null &amp;&amp; $gender_select != null)
    {
     select_weight_gender($weight_min, $weight_max, $gender_select);
     //echo "select_weight_gender";
    }
    //Height + Gender
    else if($weight_min == null &amp;&amp; $weight_max == null &amp;&amp; $height_min != null &amp;&amp; $height_max != null &amp;&amp; $gender_select != null)
    {
     select_height_gender($height_min, $height_max, $gender_select);
     //echo "select_height_gender";
    }
    //All
    else if($weight_min != null &amp;&amp; $weight_max != null &amp;&amp; $height_min != null &amp;&amp; $height_max != null &amp;&amp; $gender_select != null)
    {
     select_all($weight_min, $weight_max, $height_min, $height_max, $gender_select);
     //echo "select_all";
    }
    else if($weight_min == null &amp;&amp; $weight_max == null &amp;&amp; $height_min == null &amp;&amp; $height_max == null &amp;&amp; $gender_select == null)
    {
     select_none();
     //echo "select_none";
    }
    else
    {
     //echo "Please enter missing parameter";
    }
   
   
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//Weight only selected
   function select_weight($weight_min, $weight_max)
   {
    include 'db_connect.php';
    $result = mysqli_query($db, 
    "SELECT * FROM character_information 
    WHERE 
    (char_min_weight BETWEEN '".$weight_min."' AND '" .$weight_max."'
    OR char_max_weight BETWEEN '".$weight_min."' AND '" .$weight_max."')
    OR
    ('".$weight_min."' BETWEEN char_min_weight AND char_max_weight
    OR '" .$weight_max."' BETWEEN char_min_weight AND char_max_weight)
    ");
    
    return get_result($result);
   }
   
   //Height only selected
   function select_height($height_min, $height_max)
   {
    include 'db_connect.php';
    $result = mysqli_query($db, 
    "SELECT * FROM character_information 
    WHERE 
    (char_min_height BETWEEN '".$height_min."' AND '" .$height_max."'
    OR char_max_height BETWEEN '".$height_min."' AND '" .$height_max."')
    OR
    ('".$height_min."' BETWEEN char_min_height AND char_max_height
    OR '" .$height_max."' BETWEEN char_min_height AND char_max_height)
    ");
    
    get_result($result);
   }
   
   //Gender only selected
   function select_gender($gender_select)
   {
    include 'db_connect.php';
    
    $result = mysqli_query($db, 
    "SELECT * FROM character_information 
    WHERE char_gender = '".$gender_select."'
    "); 
    
    get_result($result); 
    
   }
   
   //Weight + Height selected
   function select_weight_height($weight_min, $weight_max, $height_min, $height_max)
   {
    include 'db_connect.php';
    
    $result = mysqli_query($db, 
    "SELECT * FROM character_information 
    WHERE 
    ((char_min_weight BETWEEN '".$weight_min."' AND '" .$weight_max."'
    OR char_max_weight BETWEEN '".$weight_min."' AND '" .$weight_max."')
    OR
    ('".$weight_min."' BETWEEN char_min_weight AND char_max_weight
    OR '" .$weight_max."' BETWEEN char_min_weight AND char_max_weight))
    AND
    ((char_min_height BETWEEN '".$height_min."' AND '" .$height_max."'
    OR char_max_height BETWEEN '".$height_min."' AND '" .$height_max."')
    OR
    ('".$height_min."' BETWEEN char_min_height AND char_max_height
    OR '" .$height_max."' BETWEEN char_min_height AND char_max_height))
    "); 
    
    get_result($result);
   }</code></pre>
  </div>
  </div>
  </p>