2013-10-15 19 views
0

我正在創建一個動態的js文件。但我有問題環路的mysql 這裏後打印的最後一個回波源:我無法在循環後回顯在動態.js上的Mysql

header('Content-Type: text/javascript; charset=UTF-8'); 
@require_once"bd.php"; 
@require_once"Funciones/funciones.php"; 

echo '$(function(){ 
      var position=0; 
      var p_control=274; 
      var num=2; 
      $(".controls .left").click(function(){getafter(p_control);}) 
      $(".controls .right").click(function(){getnext(p_control);}) 
      img=$("#sliderC ul"); 
      function getnext(number){ 
       width_img=$("#sliderC ul li").width(); 
       if(number<1230){ 
        img.animate({marginLeft: "-"+number},500); 
        p_control=number+274; 
       }else if(number>$("#sliderC ul li").size()){ 
        img.animate({marginLeft:0},500); 
        p_control=270; 
       } 
      } 
      function getafter(number){//540 
       width_img=$("#sliderC ul li").width();//127 
       if(number>270){ 
        img.animate({marginLeft:0},500); 
       } 


      } 
     }) 

$(function(){ 
    $(".title").on("mouseenter",function(){ 
     msn=$(this).attr("title");//$(this).removeAttr("title"); 
     posicion = $(this).offset();   

     $("body").append("<div class=\'title-attr\' style=\'display:none;\'>"+msn+"<span></span></div>"); 

     width_o=$(".title").outerWidth();//div - objeto seleccionado 
     width_t=$(".title-attr").outerWidth();//div del title 

     if(width_o < width_t){ 
      left=(width_t-width_o)/2; 
      $(".title-attr").css("left",posicion.left-left); 
      $(".title-attr").css("top",posicion.top-30); 
      $(".title-attr").css("display","block"); 
     }else if(width_o > width_t){ 
      left=(width_o-width_t)/2; 
      $(".title-attr").css("left",posicion.left+left); 
      $(".title-attr").css("top",posicion.top-30); 
      $(".title-attr").css("display","block"); 
     } 
     $(".title-attr span").css("left",(width_t-9)/2); 
    }) 
    $(".title").on("mouseleave",function(){ 
     $(".title-attr").remove(); 

    }) 
}) 
$(function(){ 
    $(".relaci").click(function(){ 
     $(".poster").remove(".poster"); 
     design=$("#design"); 
     position=design.position();left=design.outerWidth(); 
     design.append("'; 

     echo '<div class=\"poster\" style=\"top:"+(position.top+20)+"px;left:"+position.left+"px;\"><ul>'; 
      [email protected]_query("SELECT * FROM movies ORDER by id desc LIMIT 3"); 
      while($i=mysql_fetch_array($x) or die(mysql_error())){ 
       echo "<li>name movie: ".$i['name']."</li>"; 
      } 
     echo '</ul></div>"); 
     $(".poster").fadeIn(); 
    }) 
    $(".info").click(function(){ 
     $(".poster").fadeOut(); 
     $(".poster").remove(".poster"); 
    })  
})'; 

問題是最後的「生態」,不要在打印輸出(回聲後MySQL的循環)

回答

1

刪除該位:or die(mysql_error())

mysql_fetch_array將返回false一旦沒有更多的行要獲取。這很正常,不是錯誤。一旦它返回錯誤PHP評估or部分,它告訴它一旦打印最後一行就退出,這就是爲什麼你看不到最後一個回顯。

+0

是該行導致問題 –

0

更換

while($i=mysql_fetch_array($x) or die(mysql_error())) 

while($i=mysql_fetch_array($x))