我想使用PHP从数据库中播放我的视频,因为我将video
标记放在我的echo
语句中,视频无法播放。请告诉我我做错了什么
<?php
$query1 = mysql_query("select * from video_title where id='541' and status=1");
while($qry1 = mysql_fetch_array($query1)) {
$vid = $qry1['video']; ?>
<video style="border:1px solid" id="myVideo" width="320" height="176" controls >
<source src="<?php echo $vid;?>" type="video/mp4">
</video>
<br>
<button onclick="slowPlaySpeed()" type="button"><img src="../user/img/download.jpg" title="Slow Play" height="30px"></button>
<button style="margin-left:45px" onclick="nrmlPlaySpeed()" type="button"> play normal</button>
<button style="margin-left:45px" onclick="fastPlaySpeed()" type="button"><img src="../user/img/arrowRight.gif" title="Fast Play" height="30px"> </button>
<script>
// Get the video element with id="myVideo"
var vid = document.getElementById("myVideo");
// Set the current playback speed of the video to 0.3 (slow motion)
function slowPlaySpeed() {
vid.playbackRate = 0.3;
}
function nrmlPlaySpeed() {
vid.playbackRate = 1.0;
}
function fastPlaySpeed() {
vid.playbackRate = 5.0;
}
// Assign an onratechange event to the video element, and execute a function if the playing speed of the video is changed
</script>
<? }?>
答案 0 :(得分:0)
//mysql query
$sql = "select * from video_title where id='541' and status=1";
$result = mysql_query($conn, $sql); //$conn should be db query
while($row = mysql_fetch_array($result , MYSQL_ASSOC)){
$vid=$row['video'];
?>
<video width="100%" controls>
<source src="<?php echo $vid ?>;" type="video/mp4">
</video>
<?php
}
答案 1 :(得分:0)
您应将html
和javascript
代码置于while
循环之外
您应该使用mysqli_query($conn, $sql)
代替mysql_query($sql)
。
自PHP 5.5.0起,所有mysql_functions
都已弃用。因此不再使用它们。
<?php
$query1 = mysqli_query($conn, "select * from video_title where id='541' and status=1");
while ($qry1 = mysqli_fetch_assoc($query1)) {
$vid = $qry1["video"];
}
?>
<video width="100%" controls>
<source src="<?php echo $vid ?>;" type="video/mp4">
</video>
<br>
<button onclick="slowPlaySpeed()" type="button"><img src="../user/img/download.jpg" title="Slow Play" height="30px"></button>
<button style="margin-left:45px" onclick="nrmlPlaySpeed()" type="button"> play normal</button>
<button style="margin-left:45px" onclick="fastPlaySpeed()" type="button"><img src="../user/img/arrowRight.gif" title="Fast Play" height="30px"></button>
<script>
var vid = document.getElementById("myVideo");
function slowPlaySpeed() {
vid.playbackRate = 0.3;
}
function nrmlPlaySpeed() {
vid.playbackRate = 1.0;
}
function fastPlaySpeed() {
vid.playbackRate = 5.0;
}
</script>