php data variables (img, name, id, etc. are populated from the database as a multidimensional array. using js. to select the smaller thumbnails and change the larger displayed img and info to the selected thumbnail. it's almost working! Img changes but only changes the last info in the array?
<!-----GALLERY_IMAGES----->
<?php
$sql = "SELECT * FROM products WHERE subject LIKE '%$subject%' OR
alt_name LIKE '%$subject%'";
$total = mysqli_query($conn, $sql);
$array = array();
while ($column = mysqli_fetch_assoc($total)) {
$id = $column['id'];
$name = $column['name'];
$img = $column['img'];
$catagory = $column['catagory'];
$array[] = array(
"id" => $id,
"name" => $name,
"img" => $img,
"designer" => $designer,
"catagory" => $catagory,);
$itemArray .=
'<img src="img_prd/' . $img . '"
input id="prdName"
type="hidden"
value="' . $name . '"
onclick="swapName()"/>';}
?>
<div class="images">
<div class="imgs"><?php
echo($itemArray);
?>
</div>
// JavaScript Document
<!-----REPLACE-img----->
const current = document.querySelector("#current");
const imgs = document.querySelectorAll(".imgs img");
const opacity = 0.6;
imgs[0].style.opacity = opacity;
imgs.forEach(img => img.addEventListener("click", imgClick));
function imgClick(e) {
imgs.forEach(img => (img.style.opacity = 1));
current.src = e.target.src;
current.classList.add("fade-in");
setTimeout(() => current.classList.remove("fade-in"), 500);
e.target.style.opacity = opacity;`}`
<!-----REPLACE-NAME----->
<script>
document.querySelectorAll(".imgs img").getElementById("prdName")
.onclick = function() {swapName()};
function swapName(){
document.getElementById('currentProfile')
.setAttribute('value', '<?php echo $name ?>');
</script>