Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Lightbox with SQL

i'm trying to create a Lightbox Image Gallery using a SQL Database.

I'm storing the images as Image Hoster links in my database.

It is only showing one image using my code. Is it possible to show all?

  $res = "SELECT * FROM user";
$result = $conn->query($res);
    while($myRow = $result->fetch_array())
    { 
        $Foto = $myRow["Foto"];
    }

 
?>

<img id="myImg" src="<?php echo $Foto; ?>">

<div id="myModal" class="modal">

<span class="close">&times;</span>

  
<img class="modal-content" id="img01">

<div id="caption"></div>
</div>


<script>

var modal = document.getElementById("myModal");


var img = document.getElementById("myImg");
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
  modal.style.display = "block";
  modalImg.src = this.src;
  captionText.innerHTML = this.alt;
}


var span = document.getElementsByClassName("close")[0];


span.onclick = function() {
  modal.style.display = "none";
}
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I managend to load all Images and i can open the first image onclick. How can i open all images onclick?

<?php
$res = "SELECT * FROM user";
$result = $conn->query($res);
   while($myRow = $result->fetch_array())
   { 
       echo "<tr>";
       echo "<span class='Gallerie'>" . $myRow['Foto'] . "</span>";
       echo "</tr>";
       
   }
   


?>

<div id="myModal" class="modal">

 
 <span class="close">&times;</span>

 
 <img class="modal-content" id="img01">
 
 <div id="caption"></div>
</div>
<script>

var modal = document.getElementById("myModal");


var img = document.getElementById("image");
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
 modal.style.display = "block";
 modalImg.src = this.src;
 captionText.innerHTML = this.alt;
}


var span = document.getElementsByClassName("close")[0];


span.onclick = function() {
 modal.style.display = "none";
}
  </script>    
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!