如何从db获取事件值并将其放在js日历上

时间:2017-10-14 02:18:03

标签: javascript php

我的php文件名为view2.php:

<?php
 include('db.php');
  $select=mysqli_query($conn,"SELECT * FROM reservations where reservation_status ='CLAIMED' ");
 while($userrow = mysqli_fetch_array($select)){
     $reservationid=$userrow['reservation_id'];
     $rtype=$userrow['room_type'];
     $rstart=$userrow['reservation_start_date'];
     $cname = $userrow['customer_name'];
     $rend=$userrow['reservation_end_date'];
     //$username=$userrow['username'];
     //$password=$userrow['password'];
?>
<script>
var str = $rstart;
    var year1 = str.substring(0, 4);
    var month1 = str.substring(6, 7);
    var day1 = str.substring(9, 10);
</script>
 <?php }

funtion js_output(){
        return {
        title          : 'STANDARD',
        start          : (year1, month1, day1),
        end          : (year1, month1, day1),
        backgroundColor: 'red',
        borderColor    : 'pink'
        },
}

   ?>    

它从db获取事件,并据说在我的js文件上打印出部分脚本。完整的日历脚本:

<script>
  $(function () {
    var s = document.getElementById("START");
    var date = new Date()
    var d    = date.getDate(),
        m    = date.getMonth(),
        y    = date.getFullYear()


    $('#calendar').fullCalendar({
      header    : {
        left  : 'prev,next today',
        center: 'title',
        right : 'month,agendaWeek,agendaDay'
      },

      events    : [
      <?php include ('view2.php')?>

      ],
    })


  })
</script>

现在,我不知道为什么它不作为脚本的一部分打印。它只是在页面上回应。然后我用这段代码替换它:

<script>
  $(function () {
    var s = document.getElementById("START");
    var date = new Date()
    var d    = date.getDate(),
        m    = date.getMonth(),
        y    = date.getFullYear()


    $('#calendar').fullCalendar({
      header    : {
        left  : 'prev,next today',
        center: 'title',
        right : 'month,agendaWeek,agendaDay'
      },

      events    : [
      <?php 
      header("Content-type: application/x-javascript");
      ?>
        var i = '<?php include( 'view2.php'); echo addslashes( js_output()); ?>';
    console.log( i );
      ],
    })
  })
</script>

然后显示错误:

  

解析错误:语法错误,意外&#39; js_output&#39; (T_STRING)in   第21行的C:\ xampp \ htdocs \ system \ admin pages \ Reservations \ view2.php

2 个答案:

答案 0 :(得分:1)

第21行,将funtion替换为function

答案 1 :(得分:0)

因为它在view2.php(第21行)中显示语法错误,你可以在view2.php中共享/检查你的代码吗?

在我看来,它也可能是那个php文件中的问题。