Can't see data from MySQL into fullcalendar - php

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/

Related

how to display data from a database to display on full calendar?

I tried to display data from the database to be displayed in Full Calendar, but the data would not appear in fullcalendar, I have tried to see references in several web tutorials that integrate this, but it still hasn't worked
my reference :
https://www.patchesoft.com/fullcalendar-with-php-and-codeigniter
https://www.brianrevie.com/how-to-add-full-calendar-codeigniter
How To show fetch events from database with time in fullcalendar
I have the following data
[{"title": "Work", "start": "2019-08-01", "end": "2019-08-01" },{"title": "Work", "start": "2019-08-02","end": "2019-08-02"}]
this my js
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'dayGrid' ],
height: 440,
editable: true,
eventSources: [
{
color: '#306EFE',
textColor: '#ffffff',
events: "<?= base_url('UserDashboard/getAbsen'); ?>"
// events: [{
// title: 'My Big Event',
// start: '2019-12-09',
// end: '2019-12-10'
// },
// {
// title: 'My Second Big Event',
// start: '2019-12-11',
// end: '2019-12-13'
// },
// {
// title: 'My Second Big Event',
// start: '2019-11-11',
// end: '2019-11-13'
// },]
}
]
});
calendar.render();
});
this my controller
public function getAbsen() {
$month = date('11');
$year = date('Y');
$id_karyawan = 26;
// $data = $this->m_data->rekapAbsen($id_karyawan, $month, $year);
$data = $this->m_data->rekapAbsenFullCalendar($id_karyawan);
foreach ($data as $val) {
$id = $val["id_attendance"];
$tgl_db = $val["date_log"];
$tgl = date('Y-m-d', strtotime($tgl_db));
$d = $val["days"];
$c = $val["check_in"];
$o = $val["check_out"];
if ($d == 'Saturday') {
$days = 'Day Off';
} if ($d == 'Sunday') {
$days = 'Day Off';
} else {
if ($c == '00:00:00') {
$days = 'Day Off';
} else {
$days = 'Work';
}
}
$data_array[] = array(
// 'id_attendance' => $id,
'title' => $days,
'start' => $tgl,
'end' => $tgl,
// 'allday' => '0'
);
}
// var_dump($data);
echo json_encode($data_array);
}
and this my fullcalendar, data not showing
where is the fault?
The docs show there are a few methods of specifying a JSON feed of events.
The simplest option is just:
events: '/myfeed.php'
Alternatively, you can use the extended form if you want to also specify some options:
eventSources: [
{
url: '/myfeed.php',
color: 'yellow',
textColor: 'black'
}
Your code does not use either of these formats - you have eventSources but without a url, and with events.
Update your code as follows:
eventSources: [{
color: '#306EFE',
textColor: '#ffffff',
url: "<?= base_url('UserDashboard/getAbsen'); ?>"
}]
The rest of your code works fine, here's a working jsFiddle.

JQWidgets Combobox Typed value not being echoed or submitted to database

Below are the codes I am using,
When I selected values from the Database, they are submitted to the database, but if I type something not in the database and I want it submitted, It does not get submitted or echoed by PHP.
Sombody Please help me.
Thank You.
<?php
//Jason File
#Include the connect.php file
include('db_connect2.php');
//get county of selected district
$query = "SELECT * FROM primary_schools ";
$result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$customers[] = array(
'Emis_No' => $row['Emis_No'],
'District' => $row['District'],
'County' => $row['County'],
'Subcounty' => $row['Subcounty'],
'Parish' => $row['Parish'],
'School' => $row['School']
);
}
echo json_encode($customers);
?>
//Script
<script type=”text/javascript”>
$(document).ready(function () {
//start EMIS code
var customersSourcel =
{
datatype: "json",
datafields: [
{ name: 'Emis_No'},
{ name: 'District'},
{ name: 'County'},
{ name: 'Subcounty'},
{ name: 'Parish'},
{ name: 'School'}
],
url: 'includes/emis.php',
cache: false,
async: false
};
var customersAdapterl = new $.jqx.dataAdapter(customersSourcel);
$("#emis_no").jqxComboBox(
{
source: customersAdapterl,
width: 200,
height: 25,
promptText: "emis",
displayMember: 'Emis_No',
valueMember: 'Emis_No'
});
$("#emis_no").bind('select', function(event)
{
if (event.args)
{
var index = $("#emis_no").jqxComboBox('selectedIndex');
if (index != -1)
{
var record = customersAdapterl.records[index];
document.form1.district.value = record.District;
$("#county").jqxComboBox({ disabled: false});
document.form1.county.value = record.County;
$("#sub_county").jqxComboBox({ disabled: false});
document.form1.sub_county.value = record.Subcounty;
$("#parish").jqxComboBox({ disabled: false});
document.form1.parish.value = record.Parish;
$("#school").jqxComboBox({ disabled: false});
document.form1.school.value = record.School;
}
}
});
Initialize $customers array with $customers = array(); in the begining of the PHP file before you start pushing values into it with $customers[] = ...

FullCalendar and json events

I try to make availability calendar with FullCalendar.js. Everything works fine if I call events from database in my index.php, but when I try to get events via json I get nothing. Calendar is showing but normally, but not showing events. When I look in smjestaj-rezervacija-kalendar.php I get:
[ { title: 'Rezervirano', start: '2015-01-30', allDay: true } , { title: 'Rezervirano', start: '2015-01-31', allDay: true } , { title: 'Rezervirano', start: '2015-02-01', allDay: true } ]
so it works. Anyone having idea why it doesn't show on calendar, what am I doing wrong?
index.php
<script type="text/javascript">
$(document).ready(function(){
// Event calendar js
try{
$('#utopia-fullcalendar-2').fullCalendar({
header:{
left:'prev,next',
center:'title',
right:''
},
dayNames: ['Nedjelja','Ponedjeljak','Utorak','Srijeda','Četvrtak','Petak','Subota'],
dayNamesShort: ['Ned','Pon','Uto','Sri','Čet','Pet','Sub'],
monthNames: ['Siječanj','Veljača','Ožujak','Travanj','Svibanj','Lipanj','Srpanj','Kolovoz','Rujan','Listopad','Studeni','Prosinac'],
monthNamesShort: ['Sij','Velj','Ožu','Tra','Svi','Lip','Srp','Kol','Ruj','Lis','Stu','Pro'],
firstDay:1,
editable:false,
height:540,
events: 'smjestaj-rezervacija-kalendar.php?SmjestajID=<?=$_GET['SmjestajID'];?>'
});
} catch (e){
errorMessage(e);
}
});
</script>
and here is my smjestaj-rezervacija-kalendar.php:
<?php
header('Content-type: text/json; charset=utf-8');
include($_SERVER['DOCUMENT_ROOT']."/admin/config.php");
echo '[';
$SmjestajID = $_GET['SmjestajID'];
$rezultat_kalendar = mysqli_query($link, "SELECT * FROM smjestaj_kalendar WHERE KalendarSmjestaj=$SmjestajID ORDER BY KalendarID ASC");
$broj_unosa = mysqli_num_rows($rezultat_kalendar);
$i = 1;
while ($redak_kalendar = mysqli_fetch_array($rezultat_kalendar))
{ ?> {
title: 'Rezervirano',
start: '<?=$redak_kalendar['KalendarDatum']?>',
allDay: true
}
<?php
if ($i <> $broj_unosa){
echo ',';
}
$i ++;
}
echo ']';
?>
I try with http://fajitanachos.com/Fullcalendar-and-recurring-events/ json file, but still get nothing.
I googled and find that in json should be no html object, so I remove header('Content-type: text/json; charset=utf-8'); and go with array instead of html. This answer was helpfull: How do I get FullCalendar to display information from my JSON feed?
<?php
include($_SERVER['DOCUMENT_ROOT']."/admin/config.php");
$SmjestajID = $_GET['SmjestajID'];
$rezultat_kalendar = mysqli_query($link, "SELECT * FROM smjestaj_kalendar WHERE KalendarSmjestaj=$SmjestajID ORDER BY KalendarID ASC");
while ($record = mysqli_fetch_array($rezultat_kalendar)) {
$event_array[] = array(
'id' => $record['KalendarID'],
'title' => "Rezervirano",
'start' => $record['KalendarDatum'],
'allDay' => true
);
}
echo json_encode($event_array);
?>

How to add events in FullCalendar using an array retrieved from a mysql server (phpmyAdmin)?

I am grateful in advance of any help I receive on this. I also apologise if my error is obvious. My problem is I can't seem to find an idea on how to display all the elements of my array to populate my events.
for(var i = 0;i < count;i++)
{
// these are the arrays that contain my events
var primaryAsset = primaryAssets[i];
var release_Date = releaseDates[i];
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
weekMode: 'liquid',
weekends: true,
events: [
{
title: primaryAsset,
start: release_Date,
end: release_Date
}
]
});
}
Please create event array first then pass into full calender like
var evt = [
{
title : 'event1',
start : '2014-01-01'
},
{
title : 'event2',
start : '2014-01-05',
end : '2014-01-07'
},
{
title : 'event3',
start : '2014-01-09T12:30:00',
allDay : false
}
];
then add into full calender
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
weekMode: 'liquid',
weekends: true,
events: evt
});
This my script to get json data from php file. thats may works for you.
<script>
$('#calendar').fullCalendar(
{
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events:
{ // Render the events in the calendar
url: 'calendarData.php', // Get the URL of the json feed
error: function()
{
alert('There Was An Error While Fetching Events Or The Events Are Not Found!');
}
}
});
</script>
calendarData.php
$return_array = array();
while ($row = mysql_fetch_array($sth))
{
$event_array = array();
$event_array['id'] = $row['e_id'];
$date_start = $row['e_date_start'];
$date_end = $row['e_date_end'];
$date_start = explode(" ",$date_start);
$date_end = explode(" ", $date_end);
$date_start[0] = str_replace('-' , '/' , trim($date_start[0]));
$date_end[0] = str_replace('-' , '/' , trim($date_end[0]));
//Event Title Structure
if($row['e_title'] != "")
{
$event_array['title'] = $row['e_title'];
//Start Date Structure
if($date_start[0] != "0000/00/00" && $date_start[1] != "00:00:00")
{
$event_array['start'] = date(DATE_ISO8601, strtotime($date_start[0]." ".$date_start[1]));
}
//End Date Structure
if($date_end[0] != "0000/00/00" && $date_end[1] != "00:00:00")
{
$event_array['end'] = date(DATE_ISO8601, strtotime($date_end[0]." ".$date_end[1]));
}
//All Day Event Structure
if($row['e_allday'] == '1')
{
$event_array['allDay'] = true;
}
elseif($row['e_allday'] == '0')
{
$event_array['allDay'] = false;
}
array_push($return_array, $event_array);
}
}
echo json_encode($return_array);
Here are the steps that I took, which worked pretty slick:
1. Load the calendar, using the basic code in fullCalendar documentation:
<script>
$(document).ready(function() {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
// put your options and callbacks here
})
});
</script>
make sure you can actually pull in the data from your array (it doesn't need to be in the calendar yet, just load it onto the page to verify that it works). Something like this should do it: (note, I have not tested this code, but it is close. May need to be tweeked though)
if ( have_posts() ) :
//start a while statement
while ( have_posts() ) :
the_post();
$content_types = get_the_terms( $post_id, $taxonomy_categories );
$tag_link = get_field('tag_link');
$tag_host = parse_url($tag_link);
$tag_page = $tag_host['scheme'] . '://' . $tag_host['host'];
echo the_title();
echo the_field('date');
endwhile;
endif;
add static array, to test if the array elements will be displayed on the calendar. Use code from fullCalendar documentation:
$('#calendar').fullCalendar({
events: [
{
title : 'event1',
start : '2010-01-01'
},
{
title : 'event2',
start : '2010-01-05',
end : '2010-01-07'
},
{
title : 'event3',
start : '2010-01-09T12:30:00',
allDay : false // will make the time show
}
]
});
Finally, once everything to this point is working, replace the static data with dynamic data. You can do this by wrapping it with a loop, and getting the necessary fields through php. Here is the code that I used:
<script>
$(document).ready(function() {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
// put your options and callbacks here
events: [
//start if
<?php
if ( have_posts() ) :
//start a while statement
while ( have_posts() ) :
the_post();
$content_types = get_the_terms( $post_id, $taxonomy_categories );
$tag_link = get_field('tag_link');
$tag_host = parse_url($tag_link);
$tag_page = $tag_host['scheme'] . '://' . $tag_host['host'];
?>
{
title : '<?php the_title();?>',
start : '<?php the_field('date');?>'
//only need one item in the array, because with the while loop, this will repeat until all the posts are added.
},
<?php
endwhile;
endif;
?>
]
})
});

Jquery flot pie with PHP MYSQL

I have some problems. Excuse me for my english.
I'ld display the datas but nothing !!
I dont know where is the probleme. I dont find it.
Thnaks you for your help.
code html
<div id="pie2" style="height:300px"></div>
code javascript
jQuery(document).ready(function ($){
var options = {
series: {
pie: {
show: true,
radius: 1,
label: {
show: true,
radius: 2 / 3,
tilt:0.5,
formatter: function(label, series)
{
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">' + label + '<br/>' + Math.round(series.percent) + '% (' + series.data[0][1] + ')</div>';
},
background:
{
opacity: 0.8
}
}
}
},
legend: {
show: true
}
};
var dataset1 = <?php echo json_encode($pie);?>;
var data = [
{
"label": "Random Values",
"data": dataset1
}
];
var plotarea = $("#pie2");
$.plot( plotarea , data);
});
code PHP (source_pie.php)
$sql = "SELECT COUNT(rne) AS rne, dept FROM anuetab GROUP BY dept";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($sql)){
$pie[] = array(
'label'=>$row['dept'],
'data'=>$row['rne']
);
echo '<pre>';
print_r($pie);
echo '</pre>';
}
echo json_encode($pie);
try with mysql_fetch_row instead of mysql_fetch_assoc

Categories