PHP 在 JavaScript 集成代码中

PHP in JavaScript integration code

我尝试了几个选项,但都不起作用.... 我有一个代码

<script type="text/javascript">
                $(document).ready(function() {
    <?php
    $sql = mysql_query("SELECT * FROM `info` WHERE `active` = '1' ORDER BY `id` DESC");
    $id = 'id';
    $title = 'title';
    $content = 'content';
    while ($rows = mysql_fetch_assoc($sql)){
    ?>
                    var timeline_data = 
                   [
                        { 
                            title:    '<?php echo $rows[$title];  ?>',
                            content:  '<?php echo $rows[$content];  ?>'
                        }
                   ];
    <?php
     }
     ?>
                    var timeline = new Timeline($('#timeline'), timeline_data);
                    timeline.setOptions({
                       animation:       true,
                        lightbox:        true,
                        first_separator: true,
                        max:             2,
                        loadmore:        5,
                        separator:       'year',
                        columnMode:      'dual',
                        order:           'desc'
                    });
                    timeline.display();
                });

</script>

没有php代码,时间线工作正常,当我添加代码php,时间线不工作,没有出现,请帮助解决这个错误。谢谢

 <script type="text/javascript">
                    $(document).ready(function() {
        <?php
        $sql = mysql_query("SELECT * FROM `info` WHERE `active` = '1' ORDER BY `id` DESC");
        $id = 'id';
        $title = 'title';
        $content = 'content';
    ?>
      var timeline_data =[];
       <?php while ($rows = mysql_fetch_assoc($sql)){
        ?>
                         timeline_data[] = 

                            { 
                                title:    '<?php echo $rows[$title];  ?>',
                                content:  '<?php echo $rows[$content];  ?>'
                            }
                       ;
        <?php
         }
         ?>
                        var timeline = new Timeline($('#timeline'), timeline_data);
                        timeline.setOptions({
                           animation:       true,
                            lightbox:        true,
                            first_separator: true,
                            max:             2,
                            loadmore:        5,
                            separator:       'year',
                            columnMode:      'dual',
                            order:           'desc'
                        });
                        timeline.display();
                    });

    </script>