0

私はphpで動的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>';
            $x=@mysql_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");
    })      
})';

問題は最後の 'eco' です。出力に出力しないでください (mysql ループ後のエコー)

4

2 に答える 2

1

このビットを削除します: or die(mysql_error()).

mysql_fetch_array will return false once there are no more rows to fetch. That's normal, not an error. Once it returns false PHP evaluates the or part, which tells it to exit as soon as it's printed the last row, which is why you don't see the last echo.

于 2013-10-15T07:53:25.470 に答える
0

交換

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

while($i=mysql_fetch_array($x))
于 2013-10-15T09:23:13.957 に答える