0

I am trying to get the events for my fullCalendar implementation with the "events (as a JSON feed)" built in feature.

... event: 'calendarFill.php', ...

The php file returns the following JSON data:

[{"id":"40","title":"test four","services":"Reflexology (40), foot-soak","start":"Tue Mar 26 2013 13:00:00","end":"Tue Mar 26 2013 13:40:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test two of update. this sentence added at update.","seat":"Side Couch 9","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"},{"id":"41","title":"test four","services":"Foot-Soak, ","start":"Wed Mar 27 2013 19:00:00","end":"Wed Mar 27 2013 19:15:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test of addslashes. what's going to happen?","seat":"Front Chair 2","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"}]

The above does not work - the events are not displayed on the calendar. I've cut and pasted the code directory in my Javascript code:

events: {"id":"40","title":"test four","services":"Reflexology (40), foot-soak","start":"Tue Mar 26 2013 13:00:00","end":"Tue Mar 26 2013 13:40:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test two of update. this sentence added at update.","seat":"Side Couch 9","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"},{"id":"41","title":"test four","services":"Foot-Soak, ","start":"Wed Mar 27 2013 19:00:00","end":"Wed Mar 27 2013 19:15:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test of addslashes. what's going to happen?","seat":"Front Chair 2","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"}],

And, it does not display. But, if I edit the above to remove all the quotes that are not surrounding text values (as below), IT WORKS.

events: [{id:40,title:"test four",services:"Reflexology (40), foot-soak",start:"Tue Mar 26 2013 13:00:00",end:"Tue Mar 26 2013 13:40:00",color:"#e56b15",customerId:21,phone:"555-0404",email:"test4",notes:"test two of update. this sentence added at update.",seat:"Side Couch 9",vip:"yes",confirmed:"yes",knows_policies:"yes",customer_here:0,allDay:false},{id:41,title:"test four",services:"Foot-Soak, ",start:"Wed Mar 27 2013 19:00:00",end:"Wed Mar 27 2013 19:15:00",color:"#e56b15",customerId:21,phone:"555-0404",email:"test4",notes:"test of addslashes. what's going to happen?",seat:"Front Chair 2",vip:"yes",confirmed:"yes",knows_policies:"yes",customer_here:0,allDay:false}],

I am using the documentation at this link: http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/

What am I doing wrong? Should I remove the 'json_encode' from my php and just return a string formatted like the above? I'd like to do it the 'right' way and not some work-around.

Added the php as requested:

// for connection to db
include("../includes/config.php");
include("../includes/mysql_functions.php");

// connection with db
$linkID = db_connect();

$returnValue = array();

$getEventData = mysql_query("SELECT apt_num, services, apt_date_start, apt_date_end, therapist, customer_num, notes, seat, confirmed, knows_policies, here FROM appointments", $linkID);

if ($getEventData != FALSE && mysql_num_rows($getEventData) > 0)
{
    while ($theEventData = mysql_fetch_array($getEventData))
    {
        $getCustomerString = "SELECT first_name, middle_name, last_name, phone, email, vip FROM customer WHERE customer_num = ".$theEventData['customer_num'];
        $getCustomerData = mysql_query($getCustomerString, $linkID);

        if ($getCustomerData != FALSE && mysql_num_rows($getCustomerData) > 0)
        {
            while($theCustomerData = mysql_fetch_array($getCustomerData))
            {
                $customerName = $theCustomerData['first_name']." ".$theCustomerData['middle_name']." ".$theCustomerData['last_name'];
                $customerPhone = $theCustomerData['phone'];
                $customerEmail = $theCustomerData['email'];
                $customerVip = $theCustomerData['vip'];
            }
        }
        else
        {
            $customerName = "error";
            $customerPhone = "error";
            $customerEmail = "error";
            $customerVip = "error";
        }

        $rowArray['id'] = $theEventData['apt_num'];
        $rowArray['title'] = $customerName;
        $rowArray['services'] = $theEventData['services'];
        $rowArray['start'] = date("D", $theEventData['apt_date_start'])." ".date("M", $theEventData['apt_date_start'])." ".date("d", $theEventData['apt_date_start'])." ".date("Y", $theEventData['apt_date_start'])." ".date("H", $theEventData['apt_date_start']).":".date("i", $theEventData['apt_date_start']).":".date("s", $theEventData['apt_date_start']);
        $rowArray['end'] = date("D", $theEventData['apt_date_end'])." ".date("M", $theEventData['apt_date_end'])." ".date("d", $theEventData['apt_date_end'])." ".date("Y", $theEventData['apt_date_end'])." ".date("H", $theEventData['apt_date_end']).":".date("i", $theEventData['apt_date_end']).":".date("s", $theEventData['apt_date_end']);
        $rowArray['color'] = $theEventData['therapist'];
        $rowArray['customerId'] = $theEventData['customer_num'];
        $rowArray['phone'] = $customerPhone;
        $rowArray['email'] = $customerEmail;
        $rowArray['notes'] = $theEventData['notes'];
        $rowArray['seat'] = $theEventData['seat'];
        $rowArray['vip'] = $customerVip;
        $rowArray['confirmed'] = $theEventData['confirmed'];
        $rowArray['knows_policies'] = $theEventData['knows_policies'];
        $rowArray['customer_here'] = $theEventData['here'];
        $rowArray['allDay'] = "false";

        array_push($returnValue, $rowArray);
    }
}
else
{
    $returnValue[0] = "error";
}

print json_encode($returnValue);
seveninstl
  • 824
  • 1
  • 9
  • 17
  • What do you have in PHP file? – hjpotter92 Mar 29 '13 at 11:23
  • Customary comment: [Please, don't use `mysql_*` functions](http://stackoverflow.com/q/12859942/1190388) in new code. They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the red box? Learn about prepared statements instead, and use [tag:PDO] or [tag:MySQLi]. – hjpotter92 Mar 29 '13 at 11:35
  • On the server this is running on, the 'mysql_*' functions won't be a issue. Any ideas on why fullCalendar is not rendering the events as expected? – seveninstl Mar 29 '13 at 11:50

3 Answers3

0

Markus Vetter (from Google+) found the problem. In the original code returned from my php file there is an "'" that causes an issue. I needed to 'addslashes' to my php before returning it to the jQuery/Javascript. Once that was done, the jQuery / fullCalendar code was able to render my events as expected.

A second pair of eyes does wonders! Thank you Markus Vetter!

The original code returned:

[{"id":"40","title":"test four","services":"Reflexology (40), foot-soak","start":"Tue Mar 26 2013 13:00:00","end":"Tue Mar 26 2013 13:40:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test two of update. this sentence added at update.","seat":"Side Couch 9","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"},{"id":"41","title":"test four","services":"Foot-Soak, ","start":"Wed Mar 27 2013 19:00:00","end":"Wed Mar 27 2013 19:15:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test of addslashes. what's going to happen?","seat":"Front Chair 2","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"}]

After using 'addslashes' in my php for all text fields:

[{"id":"40","title":"test four","services":"Reflexology (40), foot-soak","start":"Tue Mar 26 2013 13:00:00","end":"Tue Mar 26 2013 13:40:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test two of update. this sentence added at update.","seat":"Side Couch 9","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"},{"id":"41","title":"test four","services":"Foot-Soak, ","start":"Wed Mar 27 2013 19:00:00","end":"Wed Mar 27 2013 19:15:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test of addslashes. what\'s going to happen?","seat":"Front Chair 2","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"}]
seveninstl
  • 824
  • 1
  • 9
  • 17
0

Actually solved this time! In my php file, the last value added to the $rowArray is: $rowArray['allDay'] = "false". Instead of being a text value, it needs to be the actual boolean value. This "$rowArray['allDay'] = false" fixed the problem.

seveninstl
  • 824
  • 1
  • 9
  • 17
0

I had the same issue and it was a formatting thing for me as well.

This is how my json is returning now and it is finally working.

[{"title":"Coke Trade Show","start":"2014-12-03"},{"title":"Michigan Show","start":"2014-12-04"}]

Definitely a good idea to paste your json return straight into the JS to make sure it is working.

jharLAN01
  • 31
  • 4