这是后续问题from here。但问题不同。
我有以下模型,print_r也是如下。
This is Model MCalendar_one/getEvents($time)
function getEvents($time){
...
$query = $this->db->query("SELECT DATE_FORMAT(eventDate,'%d') AS
day,eventContent,eventTitle FROM eventcal WHERE eventDate BETWEEN
'$current_year/$current_month/01' AND
'$current_year/$current_month/$total_days_of_current_month'");
foreach ($query->result_array() as $row_event)
{
$events = $row_event;
echo "<pre>";
print_r ($events);
echo"</pre>";
}
Print_r is this.
Array
(
[day] => 17
[eventContent] => event 1 of 17th
[eventTitle] => 17th event 1
)
Array
(
[day] => 19
[eventContent] => event 1 of 19th
[eventTitle] => 19th event 1
)
Array
(
[day] => 05
[eventContent] => event 1 of 5th
[eventTitle] => 5th event 1
)
Array
(
[day] => 17
[eventContent] => event 2 of 17th
[eventTitle] => 17th event 2
)
Array
(
[day] => 19
[eventContent] => event 2 of 19th
[eventTitle] => 19th event 2
)
Array
(
[day] => 19
[eventContent] => event 3 of 19th
[eventTitle] => 19th event 3
)
Array
(
[day] => 25
[eventContent] => birthday
[eventTitle] => birthday
)
现在我在控制器和print_r()中添加以下内容。但结果却不同。它只显示最后一个。
有人能告诉我如何显示所有数组PLZ吗?
提前致谢。
This is in Controller
$data['events']=$this->MCalendar_one->getEvents($time);
In view
print_r $events;
this displays
Array ( [day] => 25 [eventContent] => birthday [eventTitle] => birthday )
答案 0 :(得分:0)
你可能想要
$events = array();
foreach ($query->result_array() as $row_event) {
// append $row_event to $events;
$events[] = $row_event;
}
echo "<pre>events: ";
print_r($events);
echo"</pre>";
return $events;
甚至更简单
return $query->result_array();