2016-02-02 65 views
-2

我的代碼根據用戶連接速度檢索視頻。php中出乎意料的聲明

我得到的語法錯誤在我的代碼上出乎意料。我正在解決此,在過去幾天,已經用完就如何解決它的想法..

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

錯過else(($ spee。)之前的'}'結束d> = 100)&&($ count2> 0)){'。條件下也可以使用'elseif'而不是'else'。 –

回答

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 

          } 
+0

這解決了這個問題..但我得到了另一個問題,我的嵌入視頻給隨機數而不是video_link你能幫我解決這個問題嗎?嵌入式視頻輸出https:// ip address/testNxServer/trynewnew/menu/stream/video /%3Cbr%20 /%3E%3Cfont%20size ='1'%3E%3Ctable%20class ='xdebug-error%20xe -notice'%20dir ='ltr'%20border ='1'%20cellspacing ='0'%20cellpadding ='1'%3E%3Ctr%3E%3Cth%20align ='left'%20bgcolor ='#f57900'colspan = –

+0

我認爲你應該創建一個新的問題。這個問題與這個問題的標題沒有關係。 –

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'];      
        }