Answer the question
In order to leave comments, you need to log in
How to convert json from php array?
How to display data correctly
displayed data from the database and passed it to the template
in the body of the template wrote a script
$(document).ready(function() {
$('#calendar').fullCalendar({
events : [
<?php
// $datesquerysss = json_encode($datesquerysss); // не работает
foreach($datesquerysss as $task){
title : '$task->start_time'; // json_encode($task->start_time) еше один вариант не работает
start : '$task->stop_time';
}
?>
]
})
});
Answer the question
In order to leave comments, you need to log in
Horses mixed up in a bunch, people ...
In the controller, iterate over the array into a new structure that matches the required format, such as:
$events = [
'events' => [
['title' => '...', 'start ' => '...'],
['title' => '...', 'start ' => '...'],
['title' => '...', 'start ' => '...'],
['title' => '...', 'start ' => '...'],
]
];
{
"events": [
{
"title": "...",
"start ": "..."
},
{
"title": "...",
"start ": "..."
},
{
"title": "...",
"start ": "..."
},
{
"title": "...",
"start ": "..."
}
]
}
var caledarEvents = <?php echo json_encode($events); ?>;
$(document).ready(function() {
$('#calendar').fullCalendar(caledarEvents)
});
I think you should start learning from the basics.
You have mixed everything together. First, for some reason, you convert a string to Json, then you try to parse it in a loop ...
If you need data from php to javascript, then you can do this, for example:
index.html
<?php
$datesquerysss = ....
?>
<script>
var jsonstring = ' <?php echo json_encode($datesquerysss); ?> ';
......
var jsonobject = JSON.parse(jsonstring );
console.log(jsonobject);
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question