我的代码根据用户连接速度检索视频。
我的代码上出现意外的语法错误。我在过去几天对此进行了故障排除,并且已经不知道如何解决它..
ajax代码
$.ajax({
method: "POST",
url: "viewvideo.php",
data: {speedMbps: speedMbps,
video_id: $('[name="video_id"').val()},
cache: false
}).done(function( html ) {
$( "#speed" ).val( html );
});
viewvideo.php
if(isset($_POST['video_id']) && isset($_POST['speedMbps'] )){
$id = trim($_POST['video_id']);
$speed = $_POST['speedMbps'];
echo $id;
$result = mysqli_query($dbc , "SELECT `video_id`, `video_link` FROM `video480p` WHERE `video_id`='".$id."'");
$count = mysqli_num_rows($result);
if (($speed < 100) && ($count>0)) { //if user speed is less than 100 retrieve 480p quailtiy video
//does it exist?
//if($count>0){
//exists, so fetch it in an associative array
$video_480p = mysqli_fetch_assoc($result);
//this way you can use the column names to call out its values.
//If you want the link to the video to embed it;
echo $video_480p['video_link'];
}
else{
//does not exist
}
?>
<video id="video" width="640" height="480" controls autoplay>
<source src="<?php echo $video_480p['video_link']; ?>" type="video/mp4">
Your browser does not support the video tag.
</video>
<br />
<?php
$result2 = mysqli_query($dbc , "SELECT `video_id`, `video_link` FROM `viewvideo` WHERE `video_id`='".$video_id."'");
$count2 = mysqli_num_rows($result2);
// retrieve original video
else (($speed >= 100) && ($count2 >0)) {
//does it exist?
//if($count2>0){
//exists, so fetch it in an associative array
$video_arr = mysqli_fetch_assoc($result2);
//this way you can use the column names to call out its values.
//If you want the link to the video to embed it;
echo $video_arr['video_link'];
}
else{
//does not exist
}
}
?>
<video id="video" width="640" height="480" controls autoplay>
<source src="<?php echo $video_arr['video_link']; ?>" type="video/mp4">
Your browser does not support the video tag.
</video>
<br />
<?php
}
mysqli_close($dbc);
?>
答案 0 :(得分:1)
您之前没有else
语句的if
语句。
我认为你需要改变:
else (($speed >= 100) && ($count2 >0)) {
//does it exist?
//if($count2>0){
//exists, so fetch it in an associative array
$video_arr = mysqli_fetch_assoc($result2);
//this way you can use the column names to call out its values.
//If you want the link to the video to embed it;
echo $video_arr['video_link'];
}
else{
//does not exist
}
通过:
if (($speed >= 100) && ($count2 >0)) {
//does it exist?
//if($count2>0){
//exists, so fetch it in an associative array
$video_arr = mysqli_fetch_assoc($result2);
//this way you can use the column names to call out its values.
//If you want the link to the video to embed it;
echo $video_arr['video_link'];
}
else{
//does not exist
}
答案 1 :(得分:1)
您的else
应该是if
并删除}
之前的mysqli_close($dbc);
// retrieve original video
if (($speed >= 100) && ($count2 >0)) {
//does it exist?
//if($count2>0){
//exists, so fetch it in an associative array
$video_arr = mysqli_fetch_assoc($result2);
//this way you can use the column names to call out its values.
//If you want the link to the video to embed it;
echo $video_arr['video_link'];
}
``
<form id="form1" runat="server">
Name:
<input type="text" id="txtName" name="Name" value="Username" onblur="if(this.value=='')this.value='Username'"
onfocus="if(this.value=='Username')this.value='' " />
<br />
Email:
<input type="text" id="txtEmail" runat="server" value="" />
<br />
<br />
<asp:Button ID="Button1" Text="Submit" runat="server" OnClick="Submit" />