title: How to make a modal popup button for all the images I have uploaded?
body: <p>I want to make a popup modal button for all my images, but only the first works and I know that I have to add some <code>foreach</code> code, but I don't know how.</p>
  
  <pre><code>&lt;div id="myModal" class="modal"&gt;
      &lt;span class="close"&gt;&amp;times;&lt;/span&gt;
      &lt;img class="modal-content" id="img01"&gt;
  &lt;/div&gt;
  
  &lt;div class="gallery"&gt;
      &lt;div class="containerPhotos"&gt;
          &lt;?php
              require_once 'classes/dbh.php';
              if (isset($_GET['entry_id'])) {
                  $entry_id = $_GET['entry_id'];
                  $query = mysqli_query($conn, "SELECT * FROM images WHERE entry_id='$entry_id'");
  
                  if ($query-&gt;num_rows &gt; 0) {
                      while ($row = $query-&gt;fetch_assoc()) {
                          $dirname = 'uploads/' . $row["file_name"];
  
                          echo '&lt;img class="photo" onclick="showImage(this)" id="myImg" src="' . $dirname . '" /&gt;';
                      }
                  }
              }
          ?&gt;
      &lt;/div&gt;
  &lt;/div&gt;
      &lt;script&gt;
          var modal = document.getElementById('myModal');
  
          var img = document.getElementById('myImg');
          var modalImg = document.getElementById("img01");
          img.onclick = function () {
              modal.style.display = "block";
              modalImg.src = this.src;
          }
  
          var span = document.getElementsByClassName("close")[0];
  
          // When the user clicks on &lt;span&gt; (x), close the modal
          span.onclick = function () {
              modal.style.display = "none";
          }
      &lt;/script&gt;
  </code></pre>
  
  <p>I expect to work for all with a <code>foreach</code> code, but I don't know how.</p>