Welcome Guest, Not a member yet? Register   Sign In
[Solved] Codeigniter Query Misses First One Off List
#4

(This post was last modified: 12-30-2015, 02:42 AM by wolfgang1983.)

(12-29-2015, 08:45 AM)mwhitney Wrote: I don't see exactly where the problem occurs, but you should consider using a join to retrieve the results in a single query, rather than making an additional query for each result of the first query. Regardless of whether it makes it easier to generate the output, it will speed things up, especially when you have more events in the database.

I have solved it here are the changes I have had to make

Code:
public function get_calendar_events($year, $month) {
   $calendar = array();

   $events = $this->get_events($year, $month);

   foreach($events as $event) {

       $calendar[$event['day']] = '<br/>' . $event['event'];

       $extra_events = $this->get_extra_events($event['events_id']);

       foreach($extra_events as $extra_event) {
           if (array_key_exists($extra_event['day'], $calendar)) {
               $calendar[$extra_event['day']] = $calendar[$extra_event['day']] . '<br/>' .  $extra_event['event'];
           } else {
               $calendar[$extra_event['day']] =  $extra_event['event'];
           }
       }
   }


   return $calendar;
}

public function get_events($year, $month) {
   $this->db->where('year', $year);
   $this->db->where('month', $month);
   $events = $this->db->get('events');
   return $events->result_array();
}

public function get_extra_events($events_id) {
   $this->db->limit(5);
   $this->db->where('events_id', $events_id);
   $extra_events = $this->db->get('extra_events');
   return $extra_events->result_array();
}
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
RE: Codeigniter Query Misses First One Off List - by wolfgang1983 - 12-30-2015, 02:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB