I am creating a gallery in PHP. Clicking on each thumbnail should open a modal window with the image and other information.
The problem is that it only works with the first thumbnail and not with the others.
this is part of the php code:

```
        while($i !== $nIMG){
        $recordIMG = $q->fetch(PDO::FETCH_ASSOC);
        echo "<div class='content-img'><img src='". $recordIMG['urljpg'] ."' id='infoIMG'></div>";

        $i++;
    }  

```

this is the modal window

```
        <div class="modal" id="myModal">
        <img class="modal-content" id="img01">
        </div>

```

this is the javascript code

```
        var modal = document.getElementById("myModal");
        var img = document.getElementById("infoIMG");
        var modalImg = document.getElementById("img01");
        img.onclick = function(){
        modal.style.display = "block";
        modalImg.src = this.src;
     }

```

I am thinking it is an ID issue which must be unique. But I don't know how to solve, could someone more experienced help me?