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

165
Views
How to play an audio from database using php and js in html?

I'm new to js and php and tried to have music playing when mouseover my slideshow. Thing is the slideshow contains several slides obviously and I don't know how to select the right variable value to have it play... I could get $my_music to have the values of all the rows which I don't want. I would only have the right one when on the according slide. And it is all in the database, which connects just fine and everything. Only issue is this audio part...

here is my code (not the slideshow js part)


<?php include('includes/header.php')?>


<div id="my_slideshow">

<?php

$req_user = mysqli_query( $connect, "SELECT * FROM albums ORDER BY album_date ASC" );


    if ( mysqli_num_rows( $req_user ) > 0 ) {

        while ( $slide = mysqli_fetch_array( $req_user ) ) {
        
        $my_slide .= '<figure>';
        $my_slide .= '<img src="images/'.$slide[ 'album_img' ].'">';
        $my_slide .= '<figcaption>';
        $my_slide .= '<h2>'.$slide['artist_name'].'</h2>';
        $my_slide .= '<h3>'.$slide['album_name'].'</h3>';
        $my_slide .= '<p>'.'<time>'.$slide['album_date'].'</time>'.'  '.$slide['label_name'].'</p>';
        $my_slide .= '<p>©'.$slide['cover_artist'].'</p>';
        $my_slide .= '</figcaption>';
        $my_slide .= '</figure>';
        $my_music .= $slide['album_audio'];
    }
    echo($my_slide);   

}
?>

            </div>

        </article>
    </main>

<script type="text/javascript">
    var item = document.getElementById("my_slideshow");
    var music = new Audio('musics/<?php echo $my_music; ?>');
    

    item.addEventListener("mouseover", playMusic, false);
    item.addEventListener("mouseout", stopMusic, false);

    function playMusic() {
        console.log('<?php echo $my_music ?>');
        console.log('<?php echo $my_slide ?>');
        music.play();
    }

    function stopMusic() {
        music.pause();
        music.currentTime = 0;
    }

</script>

    <script type="text/javascript">
        $(document).ready(function(){
            slide_show('#my_slideshow', 4000);     
        })

    </script>

<?php include('includes/footer.php');?>```

about 4 years ago · Juan Pablo Isaza
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!