title: Modal Form to be triggered by if statement
body: <p>So i'm building a webpage, and everything on it, but one thing works fine.
  So on my "MDT" page, i select a status (eg State 0, which sends "Panic Button"), and its sent through to the database. When control.html checks the database (Every second), and picks up the "status" column saying "Panic Button", it plays an alarm. That alarm ends when my status changes.</p>
  
  <p>What i want is as well as an alarm, a modal form to pop up with basic details (eg Active State 0, Call sign, name etc)</p>
  
  <p>What i have so far:</p>
  
  <pre><code>&lt;center&gt;&lt;h2&gt;Available Units&lt;/h2&gt;
                      &lt;div id="units"&gt;
                          &lt;ul class="units"&gt;
                              &lt;?php
                                  $sql = "SELECT * FROM mdt WHERE CAD = 'NULL';";
                                  $result = mysqli_query($link, $sql);
                                  while ($row = mysqli_fetch_array($result)) {
                                      echo '&lt;li class="' . statusToClass(displayData($row['status'])) . '"&gt;' . displayData($row['callsign']) . ' - ' . displayData($row['name']) . ' &lt;span class="glyphicon glyphicon-cog editUnitBtn" aria-hidden="true"&gt;&lt;/span&gt;&lt;br/&gt;Status: ' . displayData($row['status']) . '&lt;/li&gt;';
                                  }
                              ?&gt;
                              &lt;?php
                                  $sql = "SELECT * FROM mdt WHERE status = 'Panic Button';";
                                  $result = mysqli_query($link, $sql);
                                  if ($row = mysqli_fetch_array($result)) {
                                      echo '&lt;audio autoplay="false" src="panic.mp3"&gt;';
                                      sleep(2);
                                      }
                              ?&gt;
                              &lt;?php
                                  $sql = "SELECT * FROM mdt WHERE status = 'Panic Button';";
                                  $result = mysqli_query($link, $sql);
                                  if ($row = mysqli_fetch_array($result)) {
                                       echo "&lt;script&gt;$('#panicModal').modal('show')&lt;/script&gt;";
                                       }
                              ?&gt;
  </code></pre>
  
  <p>Then near the bottom of the page:</p>
  
  <pre><code>    &lt;div class="modal fade" id="panicModal" tabindex="-1" role="dialog"&gt;
  &lt;div class="modal-dialog"&gt;
      &lt;div class="modal-content"&gt;
          &lt;div class="modal-header"&gt;
              &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
              &lt;h4 class="modal-title" id="myModalLabel"&gt;ATTENTION - ACTIVE STATE 0&lt;/h4&gt;
          &lt;/div&gt;
          &lt;div class="modal-body"&gt;
          &lt;?php
          $sql = "SELECT * FROM mdt WHERE status = 'Panic Button';";
          $result = mysqli_query($link, $sql);
          $row = mysqli_fetch_array($result);
          ?&gt;
          &lt;label&gt;Callsign&lt;/label&gt;
          &lt;?php echo displayData($row['callsign']); ?&gt;
          &lt;Label&gt;Collar Number&lt;/label&gt;
          &lt;?php echo displayData($row['name']); ?&gt; 
          &lt;Label&gt;Last Known Location&lt;/label&gt;
          &lt;?php   
          if (displayData($row['CAD']) == "NULL") {
          echo ' &lt;i&gt;Currently unassigned&lt;/i&gt;';
          } else {            
          $cadid = displayData($row['CAD']);
          $sql = "SELECT * FROM cads WHERE id = '$cadid';";
          $result = mysqli_query($link, $sql2);
          $row = mysqli_fetch_array($result2);
          echo displayData($row['location']); } ?&gt; 
          &lt;Label&gt;Call Type&lt;/label&gt;
          &lt;?php           
          if (displayData($row['CAD']) == "NULL") {
          echo ' &lt;i&gt;Currently unassigned&lt;/i&gt;';
          } else {
          $cadid = displayData($row['CAD']);
          $sql2 = "SELECT * FROM cads WHERE id = '$cadid';";
          $result2 = mysqli_query($link, $sql2);
          $row2 = mysqli_fetch_array($result2);
          echo displayData($row['type']); } ?&gt; 
          &lt;/div&gt;    
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>Any Idea's? Somewhere on the internet it mentioned putting jquery at the top of the page but when i do this it makes no difference and depending on where i put it, stops all js functions working. However with the jquery script at the bottom, everything works fine bar this bit.</p>
  
  <p>control.html : <a href="https://pastebin.com/9u6Su1uD" rel="nofollow noreferrer">https://pastebin.com/9u6Su1uD</a>
  control.js : <a href="https://pastebin.com/1FeXUN6b" rel="nofollow noreferrer">https://pastebin.com/1FeXUN6b</a></p>
  
  <p>Any help would be much appreciated.
  TIA
  Tyler</p>