Welcome Guest, Not a member yet? Register   Sign In
how can I make loop within a loop in codeigniter?
#3

[eluser]zoreli[/eluser]
First of all, thanks for your time and help. I really appreciate when people spent their time to help other people.

As for the answer...Well, I am trying to make general models. I am novice in CodeIgniter, but not novice in programming, so I am trying to reuse my code as much as I can.

Having that in mind, please take a look how I select records:

Code:
public function selectOneRecord($selectWhat = array())
        {
            $data = array();
            $rid = $selectWhat['rid'];
            $tname = $selectWhat['tname'];
            $fname = $selectWhat['fname'];
          
            $this->db->where($fname,$rid);
            $query = $this->db->get($tname,1);
            if ($query->num_rows() > 0)
            {
                $data = $query->row_array();
            }
            
            $query->free_result();
            return $data;        
        } // end of function selectOneRecord
        
        public function selectAllRecords($selectWhat = array())
        {
            $data = array();
            $tname = $selectWhat['tname'];
            $sortby = $selectWhat['sortby'];
            $how = $selectWhat['how'];
            $this->db->order_by($sortby,$how);
            $query = $this->db->get($tname);
            if($query->num_rows() > 0)
            {
                foreach($query->result_array() as $row)
                {
                    $data[] = $row;  
                }
            }
            
            $query->free_result();
            return $data;
        } // end of function selectAllRecords

In attempt to avoid creating separate function for each call, I am trying to make general models. Many people here can even make those 2 functions in one, but my knowledge is not on that level.

This example in my first post is for the table faq_categories, but I would like to use it for news_categories, products_categories etc...Thats why I wanted to avoid join.

Once again, thanks for your time and code snippet. Any other ideas are also welcomed. If you have any idea how to make the join reusable as well, it will help me a lot.

Regards, Zoreli



Messages In This Thread
how can I make loop within a loop in codeigniter? - by El Forum - 02-17-2012, 01:43 AM
how can I make loop within a loop in codeigniter? - by El Forum - 02-17-2012, 08:45 AM
how can I make loop within a loop in codeigniter? - by El Forum - 02-17-2012, 09:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB