| Issue 118: | Populating the calendar using php arrays instead of javascript | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Hello, I am trying to populate the calendar using events from mysql database using php. So far I have had no success. From the examples given, json.html is the nearest to my requirement. It uses a php file json-events.php. I want to populate the array inside json_encode with data fetched from mysql database. Can you give me any sample code to do this? Thanks Ashish
Oct 11, 2009
Is this of any use??
events: [
<?php
$query_EventStr = "SELECT * FROM tablename WHERE type = 'event' ORDER BY date ";
$EventStr = mysql_query($query_EventStr) or die(mysql_error());
$row_EventStr = mysql_fetch_assoc($EventStr);
$events = "";
do {
$events .= "{ \n\f ";
$events .= "id:'".$row_EventStr['cms_recid']."', \n\f ";
$events .= "title:'".$row_EventStr['cms_alternate']."', \n\f ";
$events .= "start:'".$row_EventStr['cms_date']."', \n\f ";
$events .= "className:'eventable', \n\f ";
// $events .= "editable:true, \n\f ";
// $events .= "end:'".date("y-m-d", $row_EventStr['cms_options'])."', \n\f ";
// $events .= "allDay:".$row_EventStr['cms_date']).", \n\f ";
$events .= "tooltip: '<p
id=\"tooltip\"><br><strong>".$row_EventStr['cms_alternate']."</strong><br/>".$row_EventStr['cms_alternate']."</p>',
\n\f ";
$events .= "url:'".$row_EventStr['cms_value']."' \n\f ";
$events .= "},";
} while ($row_EventStr = mysql_fetch_assoc($EventStr)); mysql_free_result($EventStr);
$EventStr = null;
$events = trim($events, ",");
echo $events;
?>
],
Oct 31, 2009
hi nairashish3,
and thank-you to glenza & mark for helping,
glenza's example probably won't work though, b/c it needs to be an array of arrays. so,
something like this would work...
<?php
$res = mysql_query("SELECT whatever...");
$events = array();
while ($row = mysql_fetch_assoc($res)) {
$events[] = array(
'title' => $row['title'],
'start' => $row['start'],
'end' => $row['end']
);
}
echo json_encode($events);
?>
mark's example probably works, but its usually best to collect all the events into a
single array, then spit them out w/ json_encode all at once.
hope this helps.
in the future (but who knows when), fullcalendar will come with more server-side
support (in mysql)
Status:
Done
Jan 8, 2010
m...@conkas.com can i see your sql dump of mysql table please id like to see how you have the events setup thanks Johnny |
|
| ► Sign in to add a comment |
<?php $aEvents = array('id' => $id, 'title' => $strTitle, 'start' => $startDate) $jsonEvents = json_encode($aEvents); ?>