title: What is a SMART WAY to deal with a lot of repeated If statements checks?
body: <p>In my attempt to create a searching tool for a database that I created in the context of my undergrad thesis, I am required to make a lot of checks on the values that the user has entered, and according to those values, generate and execute the appropriate <code>MySQL query</code>. An example follows:</p>
  <p><code>HTML Code</code></p>
  <pre><code>(part of the whole table)
  &lt;tr id=&quot;tablerow&quot; class=&quot;&quot;&gt;
                &lt;th id=&quot;selectth&quot;&gt;
                  &lt;select class=&quot;selection&quot; name=&quot;Attributes&quot; id=&quot;Attributes&quot;&gt;
                    &lt;!-- List of all the available attributes for the user to select for the searching queries --&gt;
                    &lt;option disabled&gt;Options&lt;/option&gt;
                    &lt;option value=&quot;Name&quot; id=&quot;p_Name&quot;&gt;Name&lt;/option&gt;
                    &lt;option value=&quot;ID&quot; id=&quot;p_Id&quot;&gt;Patient ID&lt;/option&gt;
                    &lt;option value=&quot;Sex&quot; id=&quot;p_Sex&quot;&gt;Sex&lt;/option&gt;
                    &lt;option value=&quot;Email&quot; id=&quot;p_Email&quot;&gt;Patient Email&lt;/option&gt;
                    &lt;option value=&quot;Age&quot; id=&quot;p_Age&quot;&gt;Age &gt;&lt;/option&gt;
                    &lt;option value=&quot;Agesmaller&quot;&gt;Age &lt; &lt;/option&gt;
                    &lt;option value=&quot;Race&quot; id=&quot;p_Race&quot;&gt;Race&lt;/option&gt;
                    &lt;option value=&quot;PhoneNumber&quot; id=&quot;p_Phonenum&quot;&gt;Phone Number&lt;/option&gt;
                    &lt;option value=&quot;Comorbidities&quot; id=&quot;p_Comorbidities&quot;&gt;Comorbidities&lt;/option&gt;
                    &lt;option value=&quot;EDSS&quot; id=&quot;p_eddsscore&quot;&gt;EDSS Score&lt;/option&gt;
                    &lt;option value=&quot;Pregnant&quot; id=&quot;p_Pregnant&quot;&gt;Is Pregnant&lt;/option&gt;
                    &lt;option value=&quot;Onsetlocalisation&quot; id=&quot;p_Onsetlocalisation&quot;&gt;Onset Localisation&lt;/option&gt;
                    &lt;option value=&quot;Smoker&quot; id=&quot;p_Smoker&quot;&gt;Is a Smoker&lt;/option&gt;
                    &lt;option value=&quot;onsetsymptoms&quot; id=&quot;p_onsetsymptoms&quot;&gt;Onset Symptoms&lt;/option&gt;
                    &lt;option value=&quot;MRIenhancing&quot; id=&quot;p_MRIenhancing&quot;&gt;MRI Enhancing Lesions&lt;/option&gt;
                    &lt;option value=&quot;MRInum&quot; id=&quot;p_MRInum&quot;&gt;MRI Lesion No.&lt;/option&gt;
                    &lt;option value=&quot;MRIonsetlocalisation&quot; id=&quot;p_MRIonsetlocalisation&quot;&gt;MRI Onset Localisation&lt;/option&gt;
                  &lt;/select&gt;
                &lt;/th&gt;
  </code></pre>
  <p>and as another part of that same table, I have a button that allows the user to create a second row of input in order to make a more specific search, with 2 attributes, either with AND or with an OR statement.
  <code>&lt;button type=&quot;button&quot; id=&quot;new_row_btn&quot; onclick=&quot;addRow()&quot; name=&quot;new_row&quot;&gt;Add an extra row&lt;/button&gt;</code></p>
  <p>I would like to keep this post sort in order to receive an answer, so I won't include the addRow() JavaScript function, <strong>but if it is necessary</strong> please comment it and I will edit this ASAP.</p>
  <p>My question is the following, I have those 2 inputs, and I want to check if the user has entered anything on the second row of inputs (in the &quot;advanced&quot; one) and then based on the new value execute the appropriate query.</p>
  <p>The PHP code as of now looks something like this:</p>
  <p><code>PHP Code</code></p>
  <pre><code>if($option == 'Name' &amp;&amp; $newoption == 'Email' &amp;&amp; !empty($newEmail)){
                  $sql = &quot;SELECT patients.Patient_id,patients.Patient_name,patients.DOB,patients.Phonenum,patients.Email,MSR.Sex FROM patients,MSR WHERE patients.Patient_id = MSR.NDSnum AND Doctor_ID = $usersid AND patients.Email = '$newEmail' $and_or patients.Patient_name LIKE '%$entry%' ORDER BY Patient_id&quot;;
                  $result = $pdo-&gt;query($sql);
                  if ($result-&gt;rowCount() &gt; 0) {
                    while ($row = $result-&gt;fetch()) { ?&gt;
                      &lt;table id=&quot;standard&quot;&gt;
                        &lt;tr&gt;
                          &lt;th&gt;Patient ID&lt;/th&gt;
                          &lt;th&gt;Name&lt;/th&gt;
                          &lt;th&gt;Date of Birth&lt;/th&gt;
                          &lt;th&gt;Phone Number&lt;/th&gt;
                          &lt;th&gt;Email&lt;/th&gt;
                          &lt;th&gt;Sex&lt;/th&gt;
                          &lt;th&gt;Previous Visits&lt;/th&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                          &lt;td&gt;&lt;?php echo $row['Patient_id']; ?&gt;&lt;/td&gt;
                          &lt;td&gt; &lt;?php echo $row['Patient_name']; ?&gt; &lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $row['DOB']; ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $row['Phonenum']; ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $row['Email']; ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $row['Sex']; ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo &quot;&lt;a href='/application/previousvisit-bootstrap.php?id=&quot; . $row['Patient_id'] . &quot;'&gt;Previous Visits&lt;/a&gt;&quot;; ?&gt;&lt;/td&gt;
                        &lt;/tr&gt;
                      &lt;/table&gt;
                      &lt;div class=&quot;line&quot;&gt;&lt;/div&gt;
                    &lt;?php }
                   } else {
                    echo &quot;No patient exists with this information. Name+Email&quot;;
                  }
                } if ($option == 'Name' &amp;&amp; $newoption == 'Age' &amp;&amp; !empty($newAge)){
                  $sql = &quot;SELECT * FROM patients WHERE timestampdiff(year,dob,curdate()) &gt; '$entry' $and_or patients.Patient_name LIKE '%$entry%' AND Doctor_ID = $usersid ORDER BY Patient_id&quot;;
                  $result = $pdo-&gt;query($sql);
                  if ($result-&gt;rowCount() &gt; 0) {
                    while ($row = $result-&gt;fetch()) { ?&gt;
                      &lt;table id=&quot;standard&quot;&gt;
                        &lt;tr&gt;
                          &lt;th&gt;Patient Id&lt;/th&gt;
                          &lt;th&gt;Patient Name&lt;/th&gt;
                          &lt;th&gt;Date of Birth&lt;/th&gt;
                          &lt;th&gt;Phone Number&lt;/th&gt;
                          &lt;th&gt;Email&lt;/th&gt;
                          &lt;th&gt;Previous Visits&lt;/th&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                          &lt;td&gt;&lt;?php echo $row['Patient_id']; ?&gt;&lt;/td&gt;
                          &lt;td&gt; &lt;?php echo $row['Patient_name']; ?&gt; &lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $row['DOB'] ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $row['Phonenum']; ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $row['Email']; ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo &quot;&lt;a href='/application/previousvisit-bootstrap.php?id=&quot; . $row['Patient_id'] . &quot;'&gt;Previous Visits&lt;/a&gt;&quot;; ?&gt;&lt;/td&gt;
                        &lt;/tr&gt;
                      &lt;/table&gt;
                      &lt;div class=&quot;line&quot;&gt;&lt;/div&gt;
                    &lt;?php }
                  } else {
                    echo &quot;No patient exists with this information. Name+Age&quot;;
                  }
  </code></pre>
  <p>The above if statement goes on for about 20 more times... each time checks one attribute in relation to another.. for example
  <code>Name+newID</code> or <code>ID+newName</code> or <code>Email+newSex</code>
  Obviously I know that Im not done and that there are hundreds of possible combinations with those attributes, but I was wondering if there is some way to avoid all this and make it kinda easier....</p>
  <p><strong>Im sorry for the long question!</strong> Any notes on how to make this a better question are welcome.</p>
  <p>Thank you in advanced for you time.</p>