-
Junie Member
  
-
Posts: 53
Threads: 6
Joined: May 2017
Reputation:
-1
07-09-2019, 02:10 AM
(This post was last modified: 07-09-2019, 02:11 AM by Junie.)
This is a functional search using a button click but the problem is there is no pagination on it. I wanted to insert a pagination link, I read tutorials about the CodeIgniter pagination but it only takes 1 table. The examples are a group of joints tables. below are the selected code any help/suggestions will do. I'm using CodeIgniter v2. btw, the only functional button is case 5.
This is my model:
PHP Code: public function get_schedule($to_date, $student_id = false, $from_date = false) { $this->db->select( 'schedule_class.target_date,' . 'schedule_class.id,' . 'schedule_class.student_id,' . 'schedule_class.test_flg,' . 'schedule_class.schedule_bus_id,' . 'm_class.base_class_sign' ); $this->db->from('schedule_class'); $this->db->join('m_class', 'schedule_class.student_class_id = m_class.id', 'left'); if ($student_id) { $this->db->where('schedule_class.student_id', $student_id); } if ($from_date) { $this->db->where('schedule_class.target_date >=', $from_date); } else { $this->db->where('schedule_class.target_date >=', $this->today); } if ($to_date) { $this->db->where('target_date <=', $to_date); } $this->db->where('schedule_class.presence_flg', DATA_OFF); $this->db->where('schedule_class.absence_flg', DATA_OFF); $this->db->where('schedule_class.transfer_flg', DATA_OFF); $this->db->where('schedule_class.special_transfer_flg', DATA_OFF); $this->db->order_by('schedule_class.target_date', "DESC"); $res = $this->db->get()->result_array(); return $res; }
My controller:
PHP Code: function __construct() { parent::__construct(); $this->load->model('db/l_student_reserve_change_model', 'student_reserve'); $this->load->model('db/m_course_model', 'course'); $this->load->model('db/m_class_model', 'class'); $this->load->model('db/m_grade_model', 'grade'); $this->load->model('db/reschedule_model', 'reschedule'); $this->load->library("pagination"); }
public function index() { try { $data = $this->make_data(); $data['today'] = date("Ymd"); admin_layout_view('attend_index', $data); } catch (Exception $e) { $this->_show_error($e->getMessage(), $e->getTraceAsString()); } } public function make_data() { try { $data['course_list'] = $this->course->get_list(); $data['class_alphabet'] = array("M", "A", "B", "C", "D", "E", "F"); $data['grade_info'] = $this->base->get_grade(); $this->today = date('Y-m-d 00-00-00'); $start = $this->input->post('start_date') ? $this->input->post('start_date') : $this->today; $end = $this->input->post('end_date') ? $this->input->post('end_date') : $this->today; $data['btn_kind'] = $this->input->post('sub_btn'); $list = []; switch ($data['btn_kind']) { case 1: $list = $this->reschedule->get_past_rest_list($start, $end, $student_id = false); break; case 2: $list = $this->reschedule->get_no_contact_absence_list($student_id = false, $start, $end); break; case 3: $list = $this->reschedule->get_past_attend_list($start, $student_id = false); break; case 4: $list = $this->reschedule->get_past_attend_transfer_list($start, $student_id = false); break; case 5: $list = $this->reschedule->get_schedule_list($end, $student_id = false, false); break; case 6: $list = $this->reschedule->get_tranfer_list($end, $student_id = false, $start); break; case 7: $list = $this->reschedule->get_rest_list($start, $end, $student_id = false); break; }
$data["list"] = []; foreach ($list as &$schedule_class) { $student = $this->base->get_student_now_info($schedule_class["student_id"]); if ($this->input->post('freeword')) { if ( strpos($student["id"], $this->input->post('freeword')) === false && strpos($student["name"], $this->input->post('freeword')) === false && strpos($student["name_kana"], $this->input->post('freeword')) === false ) { continue; } }
$schedule_class = array_merge($schedule_class, $student); if ($this->input->post('course')) { if (!in_array($student["course"]["id"], $this->input->post('course'))) { continue; } } if ($this->input->post('class')) { $base_class_signs = []; $match = false; foreach ($schedule_class["class"] as $class) { if (in_array($class["base_class_sign"], $this->input->post('class'))) { $match = true; } } if (!$match) { continue; } } if ($this->input->post('grade')) { if (!in_array($student["grade_id"], $this->input->post('grade'))) { continue; } } $data["list"][] = $schedule_class; }
if ($data['btn_kind'] == 4 || $data['btn_kind'] == 6) { foreach ($data["list"] as &$r) { $r["source"] = $this->db->select('*') ->from('schedule_class') ->where('id', $r["source_schedule_class_id"]) ->get() ->row_array(); $r["source_class"] = $this->reschedule->get_class_info($r["source_schedule_class_id"]); $r["transfer_class"] = $this->db->select() ->from('m_class') ->where('id', $r['student_class_id']) ->get() ->row_array(); $r["bus"] = $this->base->get_student_bus($r["student_id"]); } } $data["today_date"] = date("Ymd"); return $data; } catch (Exception $e) { $this->_show_error($e->getMessage(), $e->getTraceAsString()); } }
javasript:
Code: $("button[type='submit']").on('click', function(){
$("form[name='data_extraction']").attr('action','/admin/attend');
$("input[type='hidden']").attr('name','csv_type');
$("form[name='data_extraction']").submit();
});
-
Andryshok Junior Member
 
-
Posts: 16
Threads: 6
Joined: Apr 2015
Reputation:
0
07-09-2019, 02:17 AM
(This post was last modified: 07-09-2019, 02:18 AM by Andryshok.)
Example for bootstrap
Controller
PHP Code: $config['page_query_string'] = TRUE; $config['reuse_query_string'] = TRUE; $config['use_page_numbers'] = TRUE; $config['query_string_segment'] = 'page';
$config['total_rows'] = $total_rows; $config['per_page'] = $limit;
$config['full_tag_open'] = '<div class="pagging text-center"><nav><ul class="pagination">'; $config['full_tag_close'] = '</ul></nav></div>'; $config['num_tag_open'] = '<li class="page-item">'; $config['num_tag_close'] = '</li>'; $config['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="javascript:;">'; $config['cur_tag_close'] = '</a></li>'; $config['next_tag_open'] = '<li class="page-item">'; $config['next_tagl_close'] = '</li>'; $config['prev_tag_open'] = '<li class="page-item">'; $config['prev_tagl_close'] = '</li>'; $config['first_tag_open'] = '<li class="page-item">'; $config['first_tagl_close'] = '</li>'; $config['last_tag_open'] = '<li class="page-item">'; $config['last_tagl_close'] = '</li>'; $config['last_link'] = 'First'; $config['first_link'] = 'Last'; $config['attributes'] = array('class' => 'page-link'); $this->pagination->initialize($config); $data['pagination'] = $this->pagination->create_links();
$data['content'] = $this->load->view('view.php', $data, TRUE); $this->load->view('layout.php', $data);
View - view.php
|