学生使用codeigniter在考场分发

时间:2018-01-11 10:51:55

标签: php mysql codeigniter-3

我有三个学生表,第一个是roll_no

in roll_no table i have enrollment, center_id and roll_no

第二是中心细节

in center details table i have id, center_id, and other details

第三是房间详情

in rooms_details table i have center rooms details and center id

$anil = array();
$exam_no_students = array();
$session_usr['user']= $this->session->userdata('user_name');
$total_students['total_stu']=$this->DBfunction->totalCountAll('roll_no');
$exam_centers['no_of_centers']= $this->DBfunction->count_centers();
$exam_centers1= $this->DBfunction->count_centers();
foreach ($exam_centers1 as $center_code => $center_details){
        $center_code = array('center_id' =>$center_details->center_id);
        $center_table='exam_center';
        $center_full_details =$this->DBfunction->getArrayWhereResult($center_table,$center_code);
        foreach ($center_full_details as $full => $full_de) {
                $fullstudent = array('center_f_id' =>$full_de->center_id,
                'center_f_name' =>$full_de->exam_center,
                'center_f_addres' =>$full_de->exam_center_address ,
                'center_f_city' =>$full_de->village ,
                'center_f_count' =>$center_details->count);                             
                }
                array_push($exam_no_students, $fullstudent);
                $center_f_details =$this->DBfunction->getArrayWhereResult($center_table,$center_code);
                foreach ($center_f_details as $roomss => $rooms) {
                $room_id = array('exam_center_id' =>$rooms->id);
                $center_rooms =$this->DBfunction->getArrayWhereResult('exam_center_rooms',$room_id);
                foreach ($center_rooms as $rooms_c => $roomsdetails) {
                $center_with_rooms['anil'] = array('center_id'=>$rooms->center_id,                                                              
                'center_name'=>$rooms->exam_center,                                                             
                'center_main'=>$roomsdetails->exam_center_id,                                                               
                'no_of_students'=>$center_details->count,                                                               
                'room_no'=>$roomsdetails->room_no,                                                              
                'no_of_seating'=>$roomsdetails->noofseating,                                                                'noofrow'=>$roomsdetails->noofrow,                                                              
                'noofcol'=>$roomsdetails->noofcol
                );
   }
}

我想将学生分配到下面的考试房间

student assigned for exam and shift details

我很困惑这样做。

1 个答案:

答案 0 :(得分:0)

我使用array_slice()获得了上述查询的解决方案。并获得理想的结果。

public function Student_shift(){
            $stateus='Approved';
            $statuss = array('status' =>$stateus);
            $table ='exam_center';
            $get_centers=$this->DBfunction->getArrayWhereResult($table,$statuss);
            $new_array = array();
            foreach ($get_centers as $centers => $centers_name){
                $i=1;
                $centerid=$centers_name->center_id;
                $main_id = $centers_name->id;
                $center_where = array('center_id' =>$centerid); 
                $roll_table='roll_no';
                $all_center_student = $this->DBfunction->getArrayWhereResult($roll_table,$center_where);
                $all_center_student_count=count($all_center_student);//die;                 
                $rooms_where = array('exam_center_id' =>$main_id);
                    $room_table= 'exam_center_rooms';
                    $rooms_details= $this->DBfunction->getArrayWhereResult($room_table, $rooms_where);
                    $cout = count($all_center_student);
                    $diff_diff=$all_center_student;
                    $start =0;
                    $shift=1;
                    $rooms_seating = 0; 
                    while ($diff_diff){
                        $start =0;
                        $rooms_seating = 0;
                        $i=0;
                        ini_set('max_execution_time', 0); 
                        ini_set('memory_limit','2048M');
                    foreach ($rooms_details as $roo => $rooms_ava){                         
                         $sliced_array = array_slice($diff_diff, $start, $rooms_ava->noofseating-2);
                        $start = $rooms_ava->noofseating-2;                                                     
                            foreach ($sliced_array as $key1 => $all) {
                            $students_with_rooms = array('enrollment' =>$all->enrollment,
                                                        'center_id' =>$all->center_id,
                                                        'roll_no' =>$all->roll_no,
                                                        'stu_class' =>$all->stu_class,
                                                        'room_no' =>$rooms_ava->room_no,
                                                        'shift_id'=>$shift                                  
                             );                                 
                             $roll_where = array('roll_no' => $all->roll_no);
                             $table='roll_no';  
                             $data = array('room_no' => $rooms_ava->room_no,
                                            'shift_id'=>$shift
                            );  
                            $this->DBfunction->updateArrayWhereResult($table, $roll_where, $data);                          
                            array_push($new_array, $students_with_rooms);
                            }   
                            $rooms_seating = $rooms_seating+$rooms_ava->noofseating-2;  
                            $i++;                       
                     }
                     $diff_diff = array_slice($diff_diff, $rooms_seating);
                     $shift++;
                }                   
         }
         redirect('Admin/abcd');
    }