File name changes with loop, image is showing dynamically but sound is not


on loop the image file name is changing but audio file name is not changing so each time button play same audio while image is diffrent, i stored 52 images and sounds with 1,2,3, (.jpg and .mp3) file name in folder, with following code images are showing correctly but sound is repeating same one (only 1.mp3)

for ($x = 1; $x <= 52; $x++) {

echo $pth1.$x.".mp3";
global $filenm;
$filenm= $pth1.$x.".mp3";
echo “<img src=”$pth".$x.".jpg" width=75 height=75>

<audio id=“player” src=’$filenm’>

The number is: $x
"; } ?>[/php]



An id should be unique to a HTML page. Based on this, I would say you have several elements with the same id, but this will only grab the first one it finds. What would help you more is, uniquely identifying the other elements as well,


So that player1 is the id of sound 1 and so on.