0

I'm using this class to display a calendar: https://www.phpclasses.org/package/8426-PHP-Generate-HTML-to-display-month-event-calendars.html

I need to populate dates from a database like this one:

$calendar->events=array("2014-01-16"=>1,"2014-01-19"=>4,);

I got the following but is not working.

Any help will be appreciated. Thanks

$number = 1;    
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $response[] = array("$row['date']" => $number);
    $number++;
}
$dates = json_encode($response);
$calendar->events=array($dates);

The events are no showing on the calendar, but if I manually type the dates, like below, the events will show on the calendar.

$calendar->events=array("2014-01-16"=>1,"2014-01-19"=>4,);
3
  • Would you liie to show us the error message(s) Commented Sep 4, 2020 at 16:00
  • Thank you for responding. Actually, there are no error messages. The problem is that the dates are no passing to "$calendar->events=array" thus not showing on the calendar. Commented Sep 4, 2020 at 16:06
  • Add error reporting to the top of your file(s) while testing right after your opening PHP tag for example. Even if you are developing on a server configured as LIVE you will now see any errors. <?php error_reporting(E_ALL); ini_set('display_errors', 1); Commented Sep 4, 2020 at 16:08

1 Answer 1

1

If you are adding the values keyed by the dates, then you need something like...

$number = 1; 
$response = [];   
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $response[$row['date']] = $number++;
}

Then if you want the result encoded, you may need to use...

$calendar=json_encode([ 'events' => $dates]);
Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately, that didn't work. Nothing shows on the calendar. Thank you for your time
Have you compared the output with what you are expecting. Just saying it doesn't work isn't a way forward.

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.