student使用codeigniter在考场分发

wribegjk  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(393)

我有三张学生桌第一张是

其次是中心细节

三是客房细节

$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
                );
   }
}

我想把学生安排到下表所示的房间进行考试

我真搞不懂怎么做。

hfwmuf9z

hfwmuf9z1#

我使用array\u 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');
    }

相关问题