[英]Getting array from database
I'm using this class to display a calendar: https://www.phpclasses.org/package/8426-PHP-Generate-HTML-to-display-month-event-calendars.html我正在使用这个类来显示日历: 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,);
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]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.