0

So I was able to find the root cause of my earlier problem.

Turns out it was the querying that is the problem. Well, not on my side, at least not that I think so. This problem has been bugging me for many hours now. Unfortunately, it something I don't know how to fix.

Please check this code:

public function get_calendar_content($y,$m){

   $query = $this->db->query("SELECT * from events WHERE event_date LIKE '$y-$m%'");
   $content=array();
   foreach($query->result() as $q){
       $content[substr($q->event_date,8,2)]=$q->event_details;
   }
   return $content;

}

This function ignores whatever I supply for the $m, or the month. It only cares about the year. Plus, when I tried selecting all data from the events table instead of having a where clause, it still only returns the entries or data from the events table which is is dated in the month of August.

When I tried writing the where clause explicitly to event_date LIKE '2013-09%', it wouldn't return any data at all. I don't understand what's going on. For some unknown reason, the function would only return data from August. I already tried writing the query on phpMyAdmin, and it works just how it's supposed to do. It only produces irregularity in my app. What could my problem be?

Edit: I'm now using multidimensional array. It fixed the confusion about multiple events, but still does not return data from other months.

public function get_calendar_content($y,$m){
$query = $this->db->query("SELECT * from events WHERE event_date LIKE '$y-$m%'");
           $content=array();

       foreach($query->result() as $q){
           $content[substr($q->event_date,8,2)][]=$q->event_details;
       }
       return $content;
}
4

1 回答 1

2

问题在于您如何构建返回数组:

substr($q->event_date,8,2)将获得每个事件的日期(1-31),并且您将其用作键,但数组不能有重复键,因此只会保留最后一个值。

解决方案是更改数组的键值,以免它们重复

于 2013-08-26T17:10:30.993 回答