Insert MySQLi in JavaScript



我需要FullCalendar和JavaScript和PHP的帮助。我需要将此for for for 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>

通过更改查询,以便以所需的列名返回数据,然后使用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>

相关内容

  • 没有找到相关文章