微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

echo php导致javascript代码

我试图在javascript中回应一些PHP的结果,但它一直没有搞乱javascript播放器的界面

这是完整的JavaScript

<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){

    new jplayerPlaylist({


        jplayer: "#jquery_jplayer_1",
            cssSelectorAncestor: "#jp_container_1"
        }, [
            {
                title:"Name",
                mp3:"audio.mp3",
            },      

        ], {
            swfPath: "js",
            supplied: "oga, mp3",
            wmode: "window"
        });
    });
    //]]>
    </script>

我想替换这个:

            {
                title:"Name",
                mp3:"audio.mp3",
            },      

有了这个 :

    while(
    $row = MysqL_fetch_assoc($result)) { 
    $sender = $row['sender'];
    $sender_name_query = MysqL_query("SELECT fullname FROM users WHERE id = '$sender'");
    $sender_name = MysqL_fetch_object($sender_name_query);
    $sender_fullname = $sender_name->fullname;
    echo '{<br/>title:"' . $sender_fullname . '",<br/>mp3:"link",<br/>},';  
}   

它是一个循环我需要它来获得所有结果

任何人都可以帮助如何更换它?
谢谢

解决方法:

一个解决方案.你可以这样做:

<?PHP
    $playlist = array();

    while($row = MysqL_fetch_assoc($result)) { 
        $sender = $row['sender'];
        $sender_name_query = MysqL_query("SELECT fullname FROM users WHERE id = '$sender'");
        $sender_name = MysqL_fetch_object($sender_name_query);
        $sender_fullname = $sender_name->fullname;
        $playlist[] = (object) array(
            'title' => $sender_fullname,
            'mp3' => 'audio.mp3'
        );  
    }   
?>

<script type="text/javascript">
    //<![CDATA[
    $(document).ready(function(){
        new jplayerPlaylist({
            jplayer: "#jquery_jplayer_1",
            cssSelectorAncestor: "#jp_container_1"
        }, 
        <?PHP echo(json_encode($playlist));?>,
        {
            swfPath: "js",
            supplied: "oga, mp3",
            wmode: "window"
        });
    });
    //]]>
</script>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐