FrankGalos Posted July 30, 2015 Share Posted July 30, 2015 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 />'; } Quote Link to comment https://forums.phpfreaks.com/topic/297552-javascript-php-mysql-knowledge/ Share on other sites More sharing options...
cyberRobot Posted July 30, 2015 Share Posted July 30, 2015 Are you getting any errors? Have you been able to get an audio or video file to play before? In other words, do you know if the listen.php script works? If so, did you look at your browser's source code for the page to make sure the <a> tags are being created properly? Quote Link to comment https://forums.phpfreaks.com/topic/297552-javascript-php-mysql-knowledge/#findComment-1517754 Share on other sites More sharing options...
FrankGalos Posted July 30, 2015 Author Share Posted July 30, 2015 (edited) 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 Edited July 30, 2015 by FrankGalos Quote Link to comment https://forums.phpfreaks.com/topic/297552-javascript-php-mysql-knowledge/#findComment-1517755 Share on other sites More sharing options...
cyberRobot Posted July 30, 2015 Share Posted July 30, 2015 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? Quote Link to comment https://forums.phpfreaks.com/topic/297552-javascript-php-mysql-knowledge/#findComment-1517756 Share on other sites More sharing options...
FrankGalos Posted July 30, 2015 Author Share Posted July 30, 2015 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 Quote Link to comment https://forums.phpfreaks.com/topic/297552-javascript-php-mysql-knowledge/#findComment-1517758 Share on other sites More sharing options...
cyberRobot Posted July 30, 2015 Share Posted July 30, 2015 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: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio 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. Quote Link to comment https://forums.phpfreaks.com/topic/297552-javascript-php-mysql-knowledge/#findComment-1517759 Share on other sites More sharing options...
FrankGalos Posted July 30, 2015 Author Share Posted July 30, 2015 Cyber . thank you very much but i tested this before in my code but the player come and disappear and i don't know the solution of this Quote Link to comment https://forums.phpfreaks.com/topic/297552-javascript-php-mysql-knowledge/#findComment-1517760 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.