• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looping inside of a model

#1
[eluser]neph[/eluser]
i'm trying to run loops to count two different columns inside of a model and having a bit of trouble. am i going about this the wrong way?

Code:
if($trigger == "fields") {
            $this->db->select('name, desciption');
            $categories =     $this->db->get_fields();
    } else {
            $query = $this->db->get('fm_categories');
            $categories = $query->result();
            foreach($categories as &$category) {
                $query = $this->db->get_where('fm_threads', array('categoryId' => $category->id));
                $category->numThreads = $query->num_rows();
                $threads = $query->result();
            foreach($threads as &$thread) {
                    $this->db->where('threadId', $category->id);
                    $thread->numPosts = $this->db->count_all_results('fm_posts');
                }    
            }
        }

        return $categories;
    }


Messages In This Thread
looping inside of a model - by El Forum - 01-29-2009, 01:00 AM
looping inside of a model - by El Forum - 01-29-2009, 01:30 AM
looping inside of a model - by El Forum - 01-29-2009, 06:42 AM
looping inside of a model - by El Forum - 01-29-2009, 12:19 PM
looping inside of a model - by El Forum - 01-29-2009, 01:26 PM
looping inside of a model - by El Forum - 01-29-2009, 01:36 PM
looping inside of a model - by El Forum - 01-29-2009, 02:43 PM
looping inside of a model - by El Forum - 05-01-2009, 10:57 PM
looping inside of a model - by El Forum - 05-02-2009, 11:01 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.