0

Edit* I have found the issue. The date is being converted to this format: Mar 1 2018 12:00AM I have posted my solution below.

My query returns the appropriate results, however none of the events are showing up on the calendar.

Here's what the data looks like in SQL in case there's format issues I don't know about:

Name: Test

Start: 2009-09-23 00:00:00.000

End: 2010-04-05 00:00:00.000

PHP:

$query = mssql_query("select [NAME], [Start], [End] from [database] where [Name] = 'Test'");

       $result = array();

        if (mssql_num_rows($query)) {

            while ($row = mssql_fetch_assoc($query)) {

                $result[] = $row;
            }
        } 

        $data = array();

        foreach($result as $i => $item)
        {
         $data[] = array(
          'title'   => $item["Name"],
          'start'   => $item["Start"],
          'end'   => $item["End"]
         );
        }

JSON/JS:

<script type="text/javascript">
 $(document).ready(function() {
 var calendar = $('#calendar').fullCalendar({
 editable:true,
 header:{
 left: 'prev,next today',
  center: 'title',
  right: 'month,agendaWeek,agendaDay,listMonth'
},
events: <?php echo json_encode($data); ?> ,
selectable:true,
selectHelper:true,

})

});
</script>
8
  • Any error on the browser's console? Commented Jul 30, 2018 at 21:33
  • There is no error within the browser's console :( Commented Jul 30, 2018 at 21:42
  • Is your JSON/JS file being parsed via PHP, did you put a JSON header on it? Or is it somewhere on the PHP file? Commented Jul 30, 2018 at 21:52
  • 1
    " The date is being converted to this format: Mar 1 2018 12:00AM" probably because that's the default string format that SQL Server serialises dates to if you don't specify anything else. So yes you need to convert it to the format fullCalendar expects. You've done it in PHP in your answer which is fine, you can also do it in the SQL statement instead. It doesn't really matter either way. Commented Jul 31, 2018 at 14:28
  • 1
    I already did upvote. You're the only one who can accept the answer, since you asked the question. You're allowed to accept your own answers. AFAIK you wouldn't get banned unless you get a large number of downvotes, so far you haven't got any. Commented Jul 31, 2018 at 15:34

1 Answer 1

1

For some reason my date format was being converted, so I just converted it in the php loop:

<?php
foreach($result as $i => $item)
    {
     $data[] = array(
      'title'   => $item["Name"],
      'start'   => date("Y-m-d", strtotime($item["Start"]));
      'end'   => date("Y-m-d", strtotime($item["End"]));
     );
    }
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.