title: Dynamic Modal not displaying in table
body: <p>I have a mail system and I want to show the full email in a modal using a button in the mail table.</p>
  
  <p>I have code which is supposed to do this:</p>
  
  <pre><code>&lt;?php
  // Create connection
  $conn = new mysqli($host, $mysql_user, $mysql_pass, $db);
  // Check connection
  if ($conn-&gt;connect_error) {
  die("Connection failed: ". $conn-&gt;connect_error);
  } 
  $sql = "SELECT * FROM  `mail` ORDER BY `id` DESC";
  $result = $conn-&gt;query($sql);
  if ($result-&gt;num_rows &gt; 0) {
  
  // output data of each row
   while($row = $result-&gt;fetch_assoc()) {
  
  
  echo '&lt;tr&gt;&lt;td&gt;'.$row['name'].'&lt;/td&gt;&lt;td&gt;'.$row['subject'].'&lt;/td&gt;&lt;td&gt;'.$row['date'].'&lt;/td&gt;&lt;td&gt;&lt;button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#MyModal"&gt;Launch demo modal&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt;';
  echo '&lt;div class="modal fade"&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-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;&lt;h4 class="modal-title"&gt;'.$row['subject'].'&lt;/h4&gt;&lt;/div&gt;&lt;div class="modal-body"&gt;'.$row['message'].'&lt;/div&gt;&lt;div class="modal-footer"&gt;&lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;&lt;!-- /.modal-content --&gt;&lt;/div&gt;&lt;!-- /.modal-dialog --&gt;&lt;/div&gt;&lt;!-- /.modal --&gt;';
  }
  } else {
  echo "";
  }
  $conn-&gt;close();
  ?&gt;
  
  echo '$('#myModal').on('shown.bs.modal', function () {$('#myInput').focus()})&lt;/script&gt;'
  </code></pre>
  
  <p>But the modal doesnt display. What is going wrong and how do I fix this. Also If I place the modal button and code outside the table and outside the php its fine.</p>