Reputation: 17393
$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
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
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