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)

[php]<?php
$pth1=“voice/alifbepati/”;
$pth=“images/ipapati/”;
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’>

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

[php]document.getElementById(‘player’).play()[/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,

[php]document.getElementById(‘player{$x}’).play()[/php]

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

Sponsor our Newsletter | Privacy Policy | Terms of Service