Jump to content

javascript & php & mysql knowledge


FrankGalos

Recommended Posts

Hello friends: I have audio and video files from html form to mysql database with php. in storing data it ok but the problem is to play those data which i have already fetched them . please if there is anyone who knowlegeable and exprience in this thing. please help

 

here the code to display them

 

$sql = "SELECT * FROM music";
        $q=$con->query($sql);
        while ($row = $q->fetch_array()){
            $id = $row['id'];
            $name = $row['name'];
            $type = $row['type'];
            $fileLoc = $row['data'];
            $desc = $row['description'];
            $file = $row['file'];
            $cre = $row['created'];
            
            echo '<a href="listen.php?fl='.$fileLoc.'&f='.$file.'">'.$name.'</a> ' .$desc.'<br />';
        }

Link to comment
Share on other sites

Hello cyberRobot. thank you for your answer

That <a>tags is working fine but  that is not my purpose my purpose is to play them directly

 

What does listen.php do? Does it play the file...or does it download the file to the user's computer?

 

Also, could you provide a little more information about what you mean by "play them directly"? Since you are using a loop, I assume that there are multiple files in the database. So you probably don't want the files to automatically play once they are loaded. Are you looking to load the files into a player?

Link to comment
Share on other sites

Much thanks to you cyberRobot for not get tired at me. that listen file it's mainly purpose is to play audio file that parsed by music file that hold select queries,

 

In listen file i want to set a html5 player to play audio files from the database. that is what i was asking . and i don't know how to set php variables in html5 <audio> tags

Link to comment
Share on other sites

You could try something like this:

<?php
$sql = "SELECT * FROM music";
$q=$con->query($sql);
while ($row = $q->fetch_array()){
    $id = $row['id'];
    $name = $row['name'];
    $type = $row['type'];
    $fileLoc = $row['data'];
    $desc = $row['description'];
    $file = $row['file'];
    $cre = $row['created'];
    ?>
    <audio controls="controls">
        <source src="<?php echo $fileLoc; ?>" type="audio/wav">
    </audio>
    <?php
}
?>
 
Of course, you would need to modify the type attribute to match whatever your audio files are formatted as. More information about the syntax for the <audio> tag can be found here:
 
Also, as you loop through the files, you probably need to test whether you have an audio or video file and display the corresponding tag. I imagine you could use the if/else construct for that and the $type variable.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.