0

I'm using FullCalendar jquery plugin to display a calendar on my website. I was able to hardcode some values any it shows up fine on my calendar. The format should be:

echo json_encode(array(

        array(
            'id' => 1136,
            'title' => "Understanding Health-Care Regulations (Part II) and COBRA Compliance Strategies",
            'start' => "2011-11-17",
            'url' => "/www/conferences/conference.php?ID=1136"
        ),

        array(
            'id' => 1154,
            'title' => "Making the Most of your Membership",
            'allDay' => false,
            'start' => "Wed, 18 Nov 2011 11:00:00 EST",
            'url' => "/www/conferences/conference.php?ID=1154"
        ),
        array(
            'id' => 1137,
            'title' => "2011 Annual Human Resources Conference",
            'start' => "2011-11-29",
            'url' => "/www/conferences/conference.php?ID=1137"
        ),


    ));

When trying to mimic this array structure, I'm using this:

$conferences = dbStoredProc('cp_meeting_get_list_new');
$events = array();

foreach ($conferences as $c){
    $push = array(
        'id'        => $c['ID'],
        'title'     => $c['name'],
        'start'     => date("Y", $c['epochDate']) . "-" . date("M", $c['epochDate']) . "-" . date("d", $c['epochDate']),
        'url'       => '/events/details.php?id' . $c['ID'],
    );
    array_push($push, $events);
}
echo json_encode($events);

When I echo out my $events variable I get [].

Any ideas?

4 Answers 4

6
array_push($push, $events);

should be

array_push($events, $push);

or just

$events[] = $push;
Sign up to request clarification or add additional context in comments.

Comments

1

You're better off just appending the data to the array using

$events[] = $push;

It's faster, and less confusing than having to look up the order of parameters.

Comments

1

As xdazz said, you need to switch the arguments to array_push. Alternatively, use the [] syntax to push the item onto the end of the array:

$events[] = $push;

In addition, you can pass multiple format specifiers to date, so your start line can be written as:

date("Y-M-d", $c['epochDate']),   

Comments

0

Your PHP is flawed. Try this:

$conferences = dbStoredProc('cp_meeting_get_list_new');
$events = array();

foreach ($conferences as $c){
   $events[] = array(
       'id'        => $c['ID'],
       'title'     => $c['name'],
       'start'     => date("Y-M-d", $c['epochDate']),
       'url'       => '/events/details.php?id' . $c['ID']
    );
}
echo json_encode($events);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.