Question

Hope someone can help me. Im trying to integrate Fullcalendar (jQuery) to my website. Its version 1.6.4.

I allready have a database with content I would like to add to the calendar. I my database the raws have the names: - dispalydate (a given date for the event given in the format 2014-03-23. It should be displayed that date) - Name (title of the event) - id (id in the database)

I can see that Fullcalendar use the below code (from the file json-events.php) to show something in the calender:

<?php
$year = date('Y');
$month = date('m');
echo json_encode(array(
    array(
        'id' => 111,
        'title' => "Event1",
        'start' => "$year-$month-10",
        'url' => "http://yahoo.com/"
    ),
    array(
        'id' => 222,
        'title' => "Event2",
        'start' => "$year-$month-20",
        'end' => "$year-$month-22",
        'url' => "http://yahoo.com/"
    )
));
?>

I have replaced the above code with my own code below. I have connection to the database but nothing is showed in the Fullcalendar

<?php
// Create connection
$con=mysqli_connect("localhost","*****","*****","*****");

// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
session_start();

$result = mysql_query("SELECT id, name, displaydate AS displaydate FROM caledar");
mysql_close();
$events = array();
while ($row=mysql_fetch_array($result)){            
$id =  $row['id'];
$title = $row['name'];
$start = $row['displaydate']; 

$events = array(
'id' =>  "$id",
'name' => "$title",
'displaydate' => "$start"
);

}
echo json_encode($events);
?>

Can someone advice or see what om doing wrong?

Was it helpful?

Solution 2

I fixed the codes my self and its now working. If someone else should have the same issue, here is my code:

$query = "select * from calender";

$res = mysql_query($query) or die(mysql_error());
$events = array();
while ($row = mysql_fetch_assoc($res)) {
    $eventsArray['id'] =  $row['id'];
    $eventsArray['title'] = $row['name'];
    $eventsArray['start'] = date($row['displaydate']);
$eventsArray['url'] = 'eventlink.php?id=' . $row['id'];
$eventsArray['type'] = $row['type'];
$eventsArray['description'] = $row['description'];
    $events[] = $eventsArray;
}
echo json_encode($events);

OTHER TIPS

you should have the same names in the array you create as in the example. Replace "displaydate" with "start", and "name" with "title"

$events[] = array(
    'id' =>  "$id",
    'title' => "$title",
    'start' => "$start"
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top