S.M_Emamian
S.M_Emamian

Reputation: 17393

How to get array in CodeIgniter?

$offers variable include three value of ids. Now,I would like to fetch these ids from database and store them in $data['offer_day'] :

 $offers = explode('+',$post['offer_day']) ;

when I use this foreach, it stores just one and last query. now, how can I have three queries on $data['offer_day'] and how can use them in view ?

    foreach($offers as $o){
        $offer_day = $this->m_general->get('coupons' , array('id'=>$o) , false );
        $data['offer_day']    = $offer_day->result_array();
        if(!$data['offer_day']) exit("error");
    }

Upvotes: 0

Views: 51

Answers (2)

Lock
Lock

Reputation: 5522

Put them into an array.

$data['offer_day'] = array();
foreach($offers as $o){
    $offer_day = $this->m_general->get('coupons' , array('id'=>$o) , false );
    $data['offer_day'][]    = $offer_day->result_array();
    if(!$data['offer_day']) exit("error");
}

var_dump($data['offer_day']);

Upvotes: 1

Sanjay Kumar N S
Sanjay Kumar N S

Reputation: 4749

Update like this:

$data['offer_day'] = array();
foreach($offers as $o){
      $offer_day = $this->m_general->get('coupons' , array('id'=>$o) , false );
        $data['offer_day'][]    = $offer_day->result_array();
        if(!$data['offer_day']) exit("error");
    }

$this->load->view('your view file', $data);

And in the view file you can access like $offer_day which will be an array.

Upvotes: 1

Related Questions