I Have a ridiculous problem but even after an entire lurking day I cannot solve it.
I have a Fullcalendar installation and i'm trying to retrieve events data from a file (events.php); i load data via Php from a MySql table.
Problem:
events won't display in my calendar if i generate the feed automatically via Php.
BUT
if i write down in my file the EXACT Json line, it does work properly.
Example:
this is my events.php:
<?php session_start();
header("Content-Type: application/json");
//if (!isset($id_azienda)) die();
$id_azienda = $_GET['id_azienda'];
// Includo la classe
require_once("./db.class.php");
// Creo l'oggetto database
$db = new DataBase();
// Apro la connessione al database e ne memorizzo il risultato in $open
$open = $db->OpenConnection();
$eventiQuery = "SELECT * FROM scadenzario WHERE id_azienda ='$id_azienda'";
// Eseguo la query e ne memorizzo il risultato in $result
$eventiList = $db->Query($eventiQuery);
$numEventi = $db->NumRows($eventiQuery);
// Chiudo la connessione al database e ne memorizzo il risultato in $close
$close = $db->CloseConnection();
/* ************* FINE CARICAMENTO DATI DAL DATABASE ***************** */
while ($record = mysql_fetch_array($eventiList)) {
$event_array[] = array(
'id' => $record['id_scadenzario'],
'title' => $record['titolo'],
'start' => $record['data_inizio'],
'url' => $record['url']
);
}
echo json_encode($event_array);
?>
that will produce:
[{"id":"0","title":"test titolo","start":"2012-09-11","url":"http:\\\/\\\/yahoo.com\\\/"},{"id":"1","title":"test titolo","start":"2012-09-11","url":"http:\\\/\\\/google.com\\\/"}]
and it won't display anything.
But if i copy and paste it into the file "events.php" and comment the echo line:
// echo json_encode($event_array);
?>
[{"id":"0","title":"test titolo","start":"2012-09-11","url":"http:\\\/\\\/yahoo.com\\\/"},{"id":"1","title":"test titolo","start":"2012-09-11","url":"http:\\\/\\\/google.com\\\/"}]
it does works.
EDIT: My fullcalendar implementation is:
var scadenzario = $('#scadenzario-calendario').fullCalendar({
events: "./events.php",
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Nome dell\'evento:');
if (title) {
scadenzario.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
scadenzario.fullCalendar('unselect');
},
//editable: true,
theme: true,
buttonText: {
today: 'Oggi',
month: 'Mese',
week: 'Settimana',
day: 'Giorno'
},
monthNames: ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'],
monthNamesShort: ['Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic'],
dayNames: ['Domenica', 'Lunedi', 'Martedi', 'Mercoledi', 'Giovedi', 'Venerdi', 'Sabato'],
dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab']
});
It's kinda foolish, IMHO.
Notes:
- I read that when i try to parse just one event i can have problem with square brackets: that's not my situation, i'm trying it with two events;
- I first thought about character encoding, but i've tried text/plain and application/json, both with no luck;
- the surplus of slashes in the url is due to a lack of Gn'R sleaze hard rock style in the past few years. Lol XD (I mean: that's not the point)
- UPDATE: I tried also to create a txt with fwrite and write the json string into the file. No luck. The only way to get the work done seems to write the code by hand into the file. Well, i might consider it as a job offer, maybe. Lol.
Any ideas? Thank you in advance :)
P.s.: Sorry for italian comments and variables in the code, but that's not the point ;)