dsf4354353452 2019-08-05 10:33
浏览 45

Codeigniter查询结果

Good day! I'd like to seek some help about making a summary report page from a database. I have 4 tables in my database: 'courses' table, 'enrolment_profile' table, 'enrolment_setup' table, 'students' table

This is my desired result: Summary Report Page

So far all of my codes (controllers, models and other views) are working except the view for that desired result. Here are my working codes:

a. application/controllers/Query.php

<?php
class Query extends CI_Controller{
    public function __construct(){
        parent::__construct();
    }

    public function index(){
        $data['title'] = 'Queries';
        $this->load->view('queries', $data);
    }

    public function enrolment_summary(){
        $data['title'] = 'Enrolment Summary';

        if($this->uri->segment(3)=='view'){
            if(!isset($_POST['btnsubmit'])){
                redirect(base_url('query/enrolment_summary'));
            }
            $datestart = $this->input->post('txtdatestart');
            $dateend = $this->input->post('txtdateend');

            $this->load->model('reports_model');
            $data['students'] = $this->reports_model->query_enrolmentSummary_dateBetween($datestart,$dateend);
            $this->load->view('query_enrolment_summary', $data);
        }else{
            $this->load->view('query_form_enrolment_summary', $data);
        }
    }
}
?>

b. application/models/report_lookup_model.php

<?php
class report_lookup_model extends CI_Model{
    public function __construct(){
        parent::__construct();
        $this->load->database();
    }

    public function r_value($table, $field, $key, $return){
        $rs = $this->db->get_where($table, array($field => $key));
        $row = $rs->row();
        return $row->$return;
    }

}
?>

c. application/models/reports_model.php

<?php
class Reports_model extends CI_Model{

    public function __construct(){
        parent::__construct();
        $this->load->database();
    }

    public function query_enrolmentSummary_dateBetween($start_date, $end_date){
        $this->load->model('report_lookup_model');
        $sem = $this->report_lookup_model->r_value('enrolment_setup', 'enr_setup_id', 1, 'sem');
        $schYr = $this->report_lookup_model->r_value('enrolment_setup', 'enr_setup_id', 1, 'schYr');

        $this->db->where("date(enr_dateEnrolled) BETWEEN '$start_date' and '$end_date'");
        $rs = $this->db->get('enrolment_profile');
        return $rs->result_array();
    }

}

?>

d. application/views/queries.php

<html>
<head>
    <title><?php echo $title; ?></title>
</head>
<body>
<h1>Queries</h1>
<ul>
    <li><a href="<?php echo base_url('query/enrolled_students'); ?>">Enrolled Students</a></li>
    <li><a href="<?php echo base_url('query/not_enrolled_students'); ?>">Not Enrolled Students</a></li>
    <li><a href="<?php echo base_url('query/all_students'); ?>">All Students</a></li>
    <li><a href="<?php echo base_url('query/enrolment_summary'); ?>">Enrolment Summary</a></li>
</ul>
</body>
</html>

e. application/views/query_form_enrolment_summary.php

<html>
<head>
    <title><?php echo $title; ?></title>
</head>
<body>
    <h1><?php echo $title; ?></h1>
<?php echo form_open('query/enrolment_summary/view'); ?>
    <label>Select Start Date</label>
    <input type="date" name="txtdatestart" /> <br />

    <label>Select End Date</label>
    <input type="date" name="txtdateend" /> <br />

    <?php echo form_submit('btnsubmit', 'Submit'); ?>
<?php echo form_close(); ?>
</body>
</html>

Those are the codes that I finished already, now I just need the code for the view (application/views/query_enrolment_summary.php) of the desired result.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度