我需要有关FullCalendar、Javascript和PHP的帮助。
我需要将这个foreach PHP代码包含到这个Javascript中。

<script type="text/javascript">
$(document).ready(function() {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({

events: [


    <?php
    $sql = "SELECT * FROM eventi";
    $eventi = $mysqli->query($sql);
    foreach ($users as $row) {
      echo '{';
      echo 'title: "'.$eventi['nome'] . '"';
      echo 'start: "'.$eventi['data'] . '"';
      echo '},';
    }
      ?>
]

});
});
</script>

最佳答案

通过更改查询,使ite返回具有所需列名的数据,然后使用json_encode格式化结果,您可以
把代码简化一点。

<script type="text/javascript">
$(document).ready(function() {
    // page is now ready, initialize the calendar...
    $('#calendar').fullCalendar({
        events: [
        <?php
            $sql = "SELECT `nome` as `title`, `data` as `start` FROM eventi";
            $eventi = $mysqli->query($sql);
            $allrows = $eventi->fetch_all(MYSQLI_ASSOC);
            $rslt = json_encode($allrows);
            echo $rslt;
        ?>
        ]
    });
});
</script>

09-19 22:49