Controller print_r shows different from model print_r
This is following up question from here. But the question is different.
I have the following model and print_r is the following as well.
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
)
Now I add the following in a controller and print_r() as well. But the outcome is different. It displays only the last one.
Could anyone tell me how to dispaly all of the array plz?
Thanks in advance.
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 )
You probably want
$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;
or even simpler
return $query->result_array();
精彩评论