0
I created an agenda with fullcalendar using this project website, but when I use PHP to get the events from the database, they are not displayed in the calendar, but if I call a json shows the event normally. In the PHP file I understood that a json is generated, but I don’t know how to save it to use. If anyone knows what is wrong, I appreciate the help. Follow the code below:
Calendar.php
<script>
$(document).ready(function() {
//CARREGA CALENDÁRIO E EVENTOS DO BANCO
$('#calendario').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
//right: 'month,agendaWeek,agendaDay'
},
//defaultDate: '2016-01-12',
editable: true,
eventLimit: true,
events: 'eventos.php',
eventColor: '#dd6777'
});
});
</script>
<style>
#calendario{
position: relative;
width: 70%;
margin: 0px auto;
}
</style>
</head>
<body>
<div id='calendario'>
</div>
</body>
php events.
<?php
$conexao = mysqli_connect('', '', '', '');
$consulta = $conexao->query("SELECT event_id, title, start, end FROM eventos");
while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)){
$vetor[]= "{id:{$linha['event_id']}, title: {$linha['title']}, start: {$linha['start']}, end:{$linha['end']}}";
}
//Passando vetor em forma de json
echo json_encode($vetor);
I do not understand where this created json goes, I would like to save it paa use in the agenda, but while searching I did not find how to do this
– R.Gasparin
The json "goes" to the client when it requests, in your first code, you define
events: 'eventos.php',
, soon it calls this page. Your server executes the query, mounts JSON and returns tofullCalendar
, which is on the client’s side and executes thefullCalendar
. The problem with your code is the error when generating JSON, this is what I mentioned in the first line.– Inkeliz
But before using like this, I had tried the way you suggested, because the site I used base is used like this. It doesn’t work the way you suggested
– R.Gasparin
You changed the query so that Mysql informs the
event_id
id
with the value of? Se não você vai criar um json contendo
event_id=1e
id=1, em resumo. No seu código original você tenta utilizar
id, por isso pressuponho que ele queira o
ide não
event_id`.– Inkeliz
Yes, I changed the id na in the query call
– R.Gasparin
I can test this later, but I can’t see any other problems. See in F12 > Console if any problem is pointed out and also in F12 > Network if JSON is returned correctly.
– Inkeliz
Okay, I’ll test to see if it’s returning.
– R.Gasparin