in code igniter a group of student details check in fore-each loop ,the student get by the bases of student admission number
my admission numbers are in $ad_no=$this->input->post('adn_no'); :-
array(5) { [0]=> string(5) "11784" [1]=> string(5) "11837" [2]=> string(5) "11775" [3]=> string(5) "11937" [4]=> string(5) "12061" }
i try to select these admission numbers student, but the result show only first student result .
my code:
foreach($ad_no as $key => $id) { $this - > db - > where_in('ad_no', $id); $query = $this - > db - > get('duration'); $r = $query - > result_array(); $dur = $r[0]['tot_hr']; $start = explode(':', $dur); $end = explode(':', $tm); $total_hours = $start[0] - $end[0]; $total_hours1 = $start[1] - $end[1]; $mins = abs($total_hours1); $dur = $total_hours.":".$mins; $durs[$key] = array( 'ad_no' => $ad_no[$key], 'tot_hr' => $dur ); } $reslt = $this - > Daily_temp_model - > duration($durs);
1 Answers
Answers 1
using array push in foreach loop
$result=[]; foreach($ad_no as $key => $id) { $this->db->where_in('ad_no', $id); $query = $this-> db-> get('duration'); $r = $query-> result_array(); array_push($result, $r); $dur = $r[0]['tot_hr']; $start = explode(':', $dur); $end = explode(':', $tm); $total_hours = $start[0] - $end[0]; $total_hours1 = $start[1] - $end[1]; $mins = abs($total_hours1); $dur = $total_hours.":".$mins; $durs[$key] = array( 'ad_no' => $ad_no[$key], 'tot_hr' => $dur ); } $reslt = $this->Daily_temp_model->duration($durs);
0 comments:
Post a Comment