implementing ajax call in fullcalendar using php - php

I have already implemented full calenedar in php. It works fine . I have called the data from database and shown it in the fullcalendar.
Now I have implemented a dropdown. I have used ajax to call controller that calls my another view.
The controller fetches the data based on the dropdown selection. By default it fetches all the data.
But i am not getting the calendar after ajax call. I have called the script to load full calendar in ajax view.
When I echo in the ajax view page, i get the required data. But I am not able to display the full calendar after the ajax call.
As suggested i have give the code.
My first view:
<link rel="stylesheet" href="http://localhost/drive_training/addons/shared_addons/modules/schedule/css/fullcalendar.print.css" rel="stylesheet" media="print" />
<link rel="stylesheet" href="http://localhost/drive_training/addons/shared_addons/modules/schedule/css/fullcalendar.css" rel="stylesheet" />
<div class="content">
<div id='input'>
<?php echo form_dropdown("package_id", $packagelist, "",'id="packageid"'); ?>
</div>
<div id='calendar'></div>
</div>
<style>
#calendar {
max-width: 900px;
margin: 0 auto;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#packageid').change(function() { //any select change on the dropdown with id country trigger this code
var packageid = $('#packageid').val();
alert(packageid);
$.ajax({
type: "POST",
url: "<?php echo base_url('admin/schedule/scheduledetails/hel') ?>", //here we are calling our user controller and get_cities method with the country_id
data: {'packageid': packageid,},
success: function(data)
{
},
error: function() {
alert('failed');
}
});
});
});
</script>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
displayEventEnd: {
month: true,
basicWeek: true,
"default": true
},
defaultDate: '2014-11-12',
//editable: true,
eventLimit: true, // allow "more" link when too many events
events:
"<?php echo base_url('admin/schedule/scheduledetails/json');?>",
});
});
</script>
My controller hel function
public function hel()
{
$packageid = 9;//$_POST['packageid'];
// echo "hello";
$coursedetails = $this->course_m->where('course_id',$packageid)->get_all();
// echo "<pre>";print_r($coursedetails); echo "</pre>";
$scheduledetails = array();
foreach ($coursedetails as $details) {
$packagedays = $this->course_m->packagedays($details->id);
$presentdays = $this->attendance_m->count_attendance($details->id);
$startdate = $details->start_date;
$starttime = $details->start_time;
$endtime = $details->end_time;
$postponedays = 0;
//$enddate = date('Y-m-d', strtotime($details->start_date . ' + ' . $packagedays . ' days'));
$postponedays = $this->postpone_m->count_postponedays($details->id);
if ($postponedays == 0) {
$enddate = date('Y-m-d', strtotime($details->start_date . ' + ' . $packagedays . ' days'));
} else {
$add = $postponedays + $packagedays;
$enddate = date('Y-m-d', strtotime($details->start_date . ' + ' . $add . ' days'));
$postponefrom = $this->postpone_m->postponedate($details->id)->postponefrom;
$postponeto = $this->postpone_m->postponedate($details->id)->postponeto;
//echo $postponeto;die;
}
$temp = array
(
array
(
'course_id' => $details->id, //it means acutal course id
'title' => $this->training_package_m->get($details->course_id)->training_code, //course_id means packageid
'start' => $startdate . 'T' . $starttime,
'end' => $enddate . 'T' . $endtime,
'description' => 'Hello gyys how are you all',
'starttime' => $starttime,
'endtime' => $endtime,
// 'postponefrom' => $postponefrom,
//'postponeto' => $postponeto,
'postponeddays' => $postponedays,
'packagedays' => $packagedays,
),
);
$scheduledetails = array_merge($scheduledetails, $temp);
}
// echo json_encode($scheduledetails);
$data['jsondata'] = json_encode($scheduledetails);
//print_r($data['jsondata']);die;
$this->template
->title($this->module_details['name'])
->set_layout(false)
->build('admin/fullcalendarfiltered',$data);
}
My view to load through controller. i.e fullcalendarfiltered view file
<style>
#calendar {
max-width: 900px;
margin: 0 auto;
}
</style>
<div>Test Ajax</div>
<div id='calendar'></div>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
displayEventEnd: {
month: true,
basicWeek: true,
"default": true
},
defaultDate: '2014-11-22',
//editable: true,
eventLimit: true, // allow "more" link when too many events
events: "<?= $jsondata?>",
});
});
</script>
The view file displays test ajax only. when i echo the json data in view file it is echoed. But the problem is that it wont load in calendar. Infact the calendar is not displayed in fullcalendarfiltered view file

Related

Can't see data from MySQL into fullcalendar

EDIT
Is it possible to send the json data into this part:
$.each( res, function(key, row)(
{
events: [
{
title: 'All Day Event',
start: //from AJAX row['name'],
backgroundColor: "#f56954", //red
borderColor: "#f56954" //red
},
...
I am trying to add data from MysQL into fullcalendar.
Here is my fullcalendar script:
<script>
(function ($) {
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
eventLimit: true, // allow "more" link when too many events
events: {
url: 'fullcalendar/get-events.php',
//url: 'fullcalendar/myfeed.php',
error: function() {
$('#script-warning').show();
}
},
loading: function(bool) {
$('#loading').toggle(bool);
}
});
});
})(jQuery);
</script>
Where I get values from get-events.php, and here is the code:
<?php
//Set error reporting on
error_reporting(E_ALL);
ini_set("display_errors", 1);
//Include connection file
require_once('global.php');
//Json and PHP header
header('Content-Type: application/json');
$events = array();
$user = $_SESSION['username'];
$id_logged = $_SESSION['login_id'];
$search_date = "SELECT * FROM appointment WHERE id_logged = :id_logged";
$search_date_stmt = $conn->prepare($search_date);
$search_date_stmt->bindValue(':id_logged', $id_logged);
$search_date_stmt->execute();
$search_date_stmt_fetch = $search_date_stmt->fetchAll();
$search_date_stmt_count = $search_date_stmt->rowCount();
$i = 0;
foreach($search_date_stmt_fetch as $row)
{
$events[$i] = $row;
$i++;
}
echo json_encode($events);
?>
The result is show properly at the XHR:
But I can't see any of them in the calendar:
Build your response like the doc said :
$search_date_stmt_fetch = $search_date_stmt->fetchAll();
$search_date_stmt_count = $search_date_stmt->rowCount();
foreach($search_date_stmt_fetch as $row)
{
$events[] = array(
'start' => $row->your_date_start,
'end' => $row->your_date_end,
'id' => $row->your_id
...);
}
echo json_encode($events);
See the doc to know the properties you need : http://fullcalendar.io/docs/event_data/Event_Object/

Display dates on a calendar from a string using php

If I have a string in the following format from a form input:
02/08/2016, 02/09/2016, 02/10/2016, 02/17/2016
How can I show the dates as events in a calendar like http://fullcalendar.io/?
Should I convert them to an array, and then how can I convert them to an array? and how can I add more dates to that array/update it?
As I saw source file of this page, you need JSON array to create your events. At the end you have to create a string like this:
events: [
{
title: 'All Day Event',
start: '2016-01-01'
},
{
title: 'All Day Event',
start: '2016-01-07',
},
{
title: 'All Day Event',
start: '2016-01-09'
},
{
title: 'All Day Event',
start: '2016-01-16'
},
{
title: 'All Day Event',
start: '2016-01-11',
}
]
So use this code:
<?php
$s = '02/08/2016, 02/09/2016, 02/10/2016, 02/17/2016';
$s = explode(', ', $s);
$dates = [];
foreach($s as $event) {
//Fix format
$temp = explode('/', $event);
$dates[] = array('title' => 'All Day Event', 'start' => $temp[2] . '-' . $temp[1] . '-' . $temp[0] );
}
$dates = json_encode($dates);
So finally, Your whole HTML would be something like this:
<?php
$s = '02/08/2016, 02/09/2016, 02/10/2016, 02/17/2016';
$s = explode(', ', $s);
$dates = [];
foreach($s as $event) {
//Fix format
$temp = explode('/', $event);
$dates[] = array('title' => 'All Day Event', 'start' => $temp[2] . '-' . $temp[1] . '-' . $temp[0] );
}
$dates = json_encode($dates);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link rel='stylesheet' href='../lib/cupertino/jquery-ui.min.css' />
<link href='../fullcalendar.css' rel='stylesheet' />
<link href='../fullcalendar.print.css' rel='stylesheet' media='print' />
<script src='../lib/moment.min.js'></script>
<script src='../lib/jquery.min.js'></script>
<script src='../fullcalendar.min.js'></script>
<script src='../lang-all.js'></script>
<script>
$(document).ready(function() {
var currentLangCode = 'en';
// build the language selector's options
$.each($.fullCalendar.langs, function(langCode) {
$('#lang-selector').append(
$('<option/>')
.attr('value', langCode)
.prop('selected', langCode == currentLangCode)
.text(langCode)
);
});
// rerender the calendar when the selected option changes
$('#lang-selector').on('change', function() {
if (this.value) {
currentLangCode = this.value;
$('#calendar').fullCalendar('destroy');
renderCalendar();
}
});
function renderCalendar() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2016-01-12',
lang: currentLangCode,
buttonIcons: false, // show the prev/next text
weekNumbers: true,
editable: true,
eventLimit: true, // allow "more" link when too many events
events: <?php $dates ?>
});
}
renderCalendar();
});
</script>
<style>
body {
margin: 0;
padding: 0;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
font-size: 14px;
}
#top {
background: #eee;
border-bottom: 1px solid #ddd;
padding: 0 10px;
line-height: 40px;
font-size: 12px;
}
#calendar {
max-width: 900px;
margin: 40px auto;
padding: 0 10px;
}
</style>
</head>
<body>
<div id='top'>
Language:
<select id='lang-selector'></select>
</div>
<div id='calendar'></div>
</body>
</html>
In fullcalendar plugin you need date in this format "Y-m-d".
So you need to use explode() for string to array conversion and than you can use strtotime() for date format conversion.
<?php
$string = "02/08/2016, 02/09/2016, 02/10/2016, 02/17/2016";
$explodedDates = explode(",",$string); // explode with comma
$convertedDate = array();
foreach ($explodedDates as $key => $value) {
$convertedDate[] = date("Y-m-d", strtotime($value)); // conversion in correct format.
}
echo "<pre>";
print_r($convertedDate);
?>
From your question: and how can I add more dates to that array/update
it?
You can just push the value in your existing array as:
array_push($convertedDate,'2015-10-10');
print_r($convertedDate);
A calendar like http://fullcalendar.io/ is complex. The question is too broad, if you want to know how they do it.
Converting a string into an array is a good question. You can use the explode function in PHP as follows:
$inputs = explode(", ", "02/08/2016, 02/09/2016, 02/10/2016, 02/17/2016");
See http://php.net/manual/de/function.explode.php for more details.
Adding an element to an array can be done like this:
$inputs[] = "03/05/2016";
To update an array element, you have to find it first. You can search for an element of a simple array like the one above by an index such as $inputs[4]. But that might not be the best solution to uniquely identify a date, because in a calendar, you might have more than one event at the same day. Additionally, if you are dealing with thousands of events, it would be very slow to find the one that you want to update. I would recommend to look into other indexing strategies.
E.g. $inputs[year][month][day][id].
But that is only one of many possibilities.
Solution with php is as below
PHP code
<?php
$str = explode(',', str_replace(" ","","02/08/2016, 02/09/2016, 02/10/2016, 02/17/2016"));
print_r($str);
$events = array();
foreach($str as $k => $date) {
$events[$k]['title'] = 'Title';
$events[$k]['start'] = date('D M d Y H:i:s', strtotime($date));
}
?>
<script type="text/javascript">
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: <?php echo json_encode($events);?> // load events
});
});
</script>

is it the mysql i'm having trouble with? fullcalendar

i'm having trouble with fullcalendar. im not sure whether it is my php or mysql code. the calendar displays and i can add a new event but the event does not stick to the calendar. the event data does get inserted into the database but again it does not appear on the actual calendar itself.
here is the code i have so far:
index.php
<!DOCTYPE html>
<html>
<head>
<title>FullCalendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel='stylesheet' type='text/css' href='css/style.css' />
<link rel='stylesheet' type='text/css' href='css/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='css/jquery-ui-1.8.11.custom.css' />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="js/jquery-ui-1.8.11.custom.min.js"></script>
<script src='js/fullcalendar.min.js'></script>
<script src="js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript">
$(document).ready(function() {
/* global variables */
var event_start = $('#event_start');
var event_end = $('#event_end');
var event_type = $('#event_type');
var calendar = $('#calendar');
var form = $('#dialog-form');
var event_id = $('#event_id');
var format = "MM/dd/yyyy HH:mm";
/* button to add events */
$('#add_event_button').button().click(function(){
formOpen('add');
});
/** cleaning function form */
function emptyForm() {
event_start.val("");
event_end.val("");
event_type.val("");
event_id.val("");
}
/* opening form types*/
function formOpen(mode) {
if(mode == 'add') {
/* hide button Delete , Edit and display the Add*/
$('#add').show();
$('#edit').hide();
$("#delete").button("option", "disabled", true);
}
else if(mode == 'edit') {
/* hide the Add button , display the Edit and Delete*/
$('#edit').show();
$('#add').hide();
$("#delete").button("option", "disabled", false);
}
form.dialog('open');
}
/* date time picker */
event_start.datetimepicker({hourGrid: 4, minuteGrid: 10, dateFormat: 'mm/dd/yy'});
event_end.datetimepicker({hourGrid: 4, minuteGrid: 10, dateFormat: 'mm/dd/yy'});
/* initialize full calendar */
calendar.fullCalendar({
firstDay: 1,
height: 500,
editable: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
monthNames: ['January','Feburary','March','April','May','June','July','August','September','October','November','December'],
monthNamesShort: ['Jan.','Feb.','Маr','Apr.','May','Jun','Jul','Aug.','Sept.','Oct.','Nov.','Dec.'],
dayNames: ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturdat"],
dayNamesShort: ["Su","Mo","Tu","We","Th","Fr","Sa"],
buttonText: {
prev: " ◄ ",
next: " ► ",
prevYear: " << ",
nextYear: " >> ",
today: "today",
month: "month",
week: "week",
day: "day"
},
/* time format output before the event name*/
timeFormat: 'H:mm',
/* click event handler for a particular day */
dayClick: function(date, allDay, jsEvent, view) {
var newDate = $.fullCalendar.formatDate(date, format);
event_start.val(newDate);
event_end.val(newDate);
formOpen('add');
},
/* handler for event click */
eventClick: function(calEvent, jsEvent, view) {
event_id.val(calEvent.id);
event_type.val(calEvent.title);
event_start.val($.fullCalendar.formatDate(calEvent.start, format));
event_end.val($.fullCalendar.formatDate(calEvent.end, format));
formOpen('edit');
},
/* record source */
eventSources: [{
url: 'ajax.php',
type: 'POST',
data: {
op: 'source'
},
error: function() {
alert('Error connecting to the data source!');
}
}]
});
/* form handler */
form.dialog({
autoOpen: false,
buttons: [{
id: 'add',
text: 'add',
click: function() {
$.ajax({
type: "POST",
url: "ajax.php",
data: {
start: event_start.val(),
end: event_end.val(),
type: event_type.val(),
op: 'add'
},
success: function(id){
calendar.fullCalendar('renderEvent', {
id: id,
title: event_type.val(),
start: event_start.val(),
end: event_end.val(),
allDay: false
});
}
});
emptyForm();
}
},
{ id: 'edit',
text: 'edit',
click: function() {
$.ajax({
type: "POST",
url: "ajax.php",
data: {
id: event_id.val(),
start: event_start.val(),
end: event_end.val(),
type: event_type.val(),
op: 'edit'
},
success: function(id){
calendar.fullCalendar('refetchEvents');
}
});
$(this).dialog('close');
emptyForm();
}
},
{ id: 'cancel',
text: 'cancel',
click: function() {
$(this).dialog('close');
emptyForm();
}
},
{ id: 'delete',
text: 'delete',
click: function() {
$.ajax({
type: "POST",
url: "ajax.php",
data: {
id: event_id.val(),
op: 'delete'
},
success: function(id){
calendar.fullCalendar('removeEvents', id);
}
});
$(this).dialog('close');
emptyForm();
},
disabled: true
}]
});
});
</script>
</head>
<body>
<div id="calendar"></div>
<button id="add_event_button">Add Event</button>
<div id="dialog-form" title="Событие">
<p class="validateTips"></p>
<form>
<p><label for="event_type">type</label>
<input type="text" id="event_type" name="event_type" value=""></p>
<p><label for="event_start">start</label>
<input type="text" name="event_start" id="event_start"/></p>
<p><label for="event_end">end</label>
<input type="text" name="event_end" id="event_end"/></p>
<input type="hidden" name="event_id" id="event_id" value="">
</form>
</div>
</body>
</html>
ajax.php
<?php
$con=mysqli_connect("localhost","root","","fullcalendar");
$start = $_POST['start'];
$end = $_POST['end'];
$type = $_POST['type'];
$op = $_POST['op'];
$id = $_POST['id'];
switch ($op) {
case 'add':
$sql = 'INSERT INTO events (
start,
end,
type)
VALUES
("' . date("Y-m-d H:i:s", strtotime($start)) . '",
"' . date("Y-m-d H:i:s", strtotime($end)) . '",
"' . $type . '")';
if (mysqli_query($GLOBALS["___mysqli_ston"], $sql)) {
echo ((is_null($___mysqli_res = mysqli_insert_id($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}
break;
case 'edit':
$sql = 'UPDATE events SET start = "' . date("Y-m-d H:i:s", strtotime($start)) . '",
end = "' . date("Y-m-d H:i:s", strtotime($end)) . '",
type = "' . $type . '"
WHERE id = "' . $id . '"';
if (mysqli_query($GLOBALS["___mysqli_ston"], $sql)) {
echo $id;
}
break;
case 'source':
$sql = 'SELECT * FROM events';
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sql);
$json = Array();
while ($row = mysqli_fetch_assoc($result)) {
$json[] = array(
'id' => $row['id'],
'title' => $row['type'],
'start' => $row['start'],
'end' => $row['end'],
'allDay' => false
);
}
echo json_encode($json);
break;
case 'delete':
$sql = 'DELETE FROM events WHERE id = "' . $id . '"';
if (mysqli_query($GLOBALS["___mysqli_ston"], $sql)) {
echo $id;
}
break;
}
i'd appreciate it if there could be any constructive input or help with this issue.
Hey guys thanks for the help. I had a look at the ajax like charlietfl said and I got a few errors thrown. They were mainly errors about the database connection but seeing as the events are getting inserted to the table it didn't seem correct. I double checked the syntax of the php and mysql and it turns out I was using a few mysql functions that have been depreciated in the newest version of php. It was recommended I changed it to match the PDO or mysqli structure to see if it would work and it did. Thanks for everybody's inputs i really appreciate it.

Change jquery full calendar prompt input box to dropdown list

I am implementing jquery full calendar in my PHP website. when i am clicking on any date of calendar it is giving me a prompt. There is a input field asking for event title. I want to change this input field and want a drop down list in place of input field. Is it possible? This is the calendar that i am using http://fullcalendar.io/
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '<?php echo date("Y-m-d"); ?>',
selectable: true,
selectHelper: true,
select: function(start, end) {
var title = prompt('Please fill schedule title & add fees');
var eventData;
if (title) {
eventData = {
title: title,
url: 'javascript:fee_add("' + title + '","' + start +'");',
start: start,
end: end
};
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
}
$('#calendar').fullCalendar('unselect');
},
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
<?php
if($mysql->rowCount($query) > 0)
{
$rows = $mysql->fetchArray($query);
foreach($rows as $row)
{
if($row['date_time'] !='0000-00-00 00:00:00')
{
$date1 = date_create_from_format('Y-m-d H:i:s', $row['date_time']);
$date = date('Y-m-d', $date1->getTimestamp());
$time = date('H:i', $date1->getTimestamp());
$time_hr = date('H:i:s', $date1->getTimestamp());
}
?>
{
title: '<?php echo $row["fee_title"]; ?>',
url: 'javascript:fee_edit(<?php echo $row["id"]; ?>,"<?php echo $row["fee_title"]; ?>","<?php echo $date . " " . $time_hr; ?>");',
start: '<?php echo $date; ?>T<?php echo $time ?>'
},
<?php
}
}
?>
]
});
});
</script>
</div>
<div id='calendar'></div>
This is the code i am implementing and just want dropdown list in place of title
Thanx in advance
Prompt is a built is js component. You shouldn't attempt to override it. Try using a custom dialog/modal. jQuery UI has a great dialog component that would allow you to utilize a select element or any other html you see fit.

Unable to display database on Fullcalendar

I'm currently trying to create a JSON feed for FullCalendar. I currently have a working example, However the output doesn't get my database into the calendar. Anyone have any ideas? I've been stuck on this now..
In my codes:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href='css/fullcalendar.css' rel='stylesheet' />
<script src='js/jquery-1.9.1.min.js'></script>
<script src='js/jquery-ui-1.10.2.custom.min.js'></script>
<script src='js/fullcalendar.min.js'></script>
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
editable: true,
events : "test1.php",
eventClick: function(event) {
// opens events in a popup window
window.open(event.url, '', 'width=700,height=600');
return false;
},
loading: function(bool) {
if (bool) {
$('#loading').show();
}else{
$('#loading').hide();
}
}
});
});
</script>
<style>
body {
margin-top: 40px;
text-align: center;
font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
Code for test1.php
$link = mysql_connect('localhost','root','abc123');
if (!$link) { die('Could not connect: ' . mysql_error()); }
mysql_select_db('trainingcourse');
$result = mysql_query("SELECT * FROM tbl_course ");
Initializes a container array for all of the calendar events
$jsonArray = array();
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$eventtest = $row['courseid'];
$startdate = $row['startdate'];
$starttime = $row['starttime'];
$enddate = $row['enddate'];
$endtime = $row['endtime'];
// Stores each database record to an array
$buildjson = array('courseid' => "$eventtest", 'startdate' => "$startdate", 'enddate' => "$enddate", 'allday' => false);
// Adds each array into the container array
array_push($jsonArray, $buildjson);
}
// Output the json formatted data so that the jQuery call can read it
echo json_encode($jsonArray);
?>
It is unable to display on Calendar.
I am really appreciated for your help.
Could you try this?
<?php
$link = mysql_connect('localhost','root','abc123');
if (!$link) { die('Could not connect: ' . mysql_error()); }
mysql_select_db('trainingcourse',$link);
$result = mysql_query("SELECT * FROM tbl_course ");
while($row = mysql_fetch_assoc($result, MYSQL_ASSOC))
{
$eventtest = $row['courseid'];
$startdate = $row['startdate'];
$starttime = $row['starttime'];
$enddate = $row['enddate'];
$endtime = $row['endtime'];
// Stores each database record to an array
$buildjson[] = array(
'courseid' => $eventtest,
'startdate' => $startdate,
'enddate' => $enddate,
'allday' => false
);
}
// Output the json formatted data so that the jQuery call can read it
echo json_encode($buildjson);
?><br>
Hope it works. Please also try to print the results print_r($buildjson);
try this, it works for me
on your PHP code:
header('Content-Type: application/json');
echo json_encode($jsonArray);
on you html code:
add this option to you calendar:
eventSources: [
// your event source
{
url: 'url/of/your/jsonphp',
type: 'POST',
data: {
custom_param1: 'something',
custom_param2: 'somethingelse'
},
error: function() {
alert('there was an error while fetching events!');
},
color: '#dadada',
textColor: '#000000'
}

Categories