繁体   English   中英

Codeigniter从db获取所有行

[英]Codeigniter get all rows from db

我正在使用任务管理器,其中有两种类型的用户:管理员(所有权限)和用户(有限权限)。

这是控制器中的任务功能

function task($id) {
    $data = array(
        'query' => $this->main_model->get_task($id),
        'task_id' => $id,
        );
    $data2['comments'] = $this->main_model->get_comments($id);

    $this->load->library('form_validation');
    $this->load->helper('security');

    $this->form_validation->set_rules('comment_text', 'comment_text', 'trim|required|strip_tags|xss_clean');

    if ($this->form_validation->run() === FALSE)
    {
        if($this->main_model->get_task($id))
        {
            foreach ($this->main_model->get_task($id) as $tas)
            {
                $data = array(
                    'title' => $tas->task_name,
                    'desc' => $tas->task_description,
                    'date_created' => $tas->date,
                    'date_started' => $tas->task_start_date,
                    'deadline' => $tas->task_deadline,
                    'creator' => $tas->task_creator,
                    'owner' => $tas->task_owner, 
                    'attach'=>$tas->attachment_name,
                    'status'=>$tas->task_status,
                    'priority'=>$tas->task_priority,
                    'task_id'=>$tas->ID_task,
                    'base_url' => base_url()
                    );
            }
            $data1 = array(
                'emps' => $this->main_model->get_employees(),
                'creator' => $this->main_model->get_details($id),
                'owner' => $this->main_model->get_owner($id)
                );
             if ($this->session->userdata('employee_type') == 3) {

             $qu = $this->main_model->permission();
             $id = $this->session->userdata('id');
             $id_emp = $this->uri->segment(3);
             //foreach ($qu as $q) {
            if (in_array($id, $qu[0]) && in_array($id_emp, $qu[0])) {

                $this->load->view('task', array_merge($data, $data1, $data2));

             }
           else {
                echo "No Permission to access this task";
                }
            }
        }
    }
    else
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'doc|docx|pdf|txt|text|rtf|jpg|gif|png'; 
        $config['max_size'] = '1024';

        $this->load->library('upload', $config);

        if (!$this->upload->do_upload()) {   
            if ("You did not select a file to upload." != $this->upload->display_errors('','')) {  
                $error = array('error' => $this->upload->display_errors());
                $this->load->view('task', $error);
            }  
            else {  
                $this->main_model->set_comments($id);
                redirect(current_url());
            }  
        }  
        else {  
            $data = array('upload_data' => $this->upload->data());
            $data1 = $this->upload->data();
            $data2 = $data1['file_name'];
            $this->main_model->set_comments($id);
            $this->main_model->set_attachment($id, $data2);
            redirect(current_url());
        }  
    }

}

和我在模型中的权限功能:

function permission() {
    $query = $this->db->get('employees_tasks');
    $ret = $query->result_array();


    return $ret;
}

我要做的是,从数据库employee_tasks获取所有数据,检查ID_taskID_employee是否在数据库中的同一行,但我无法使其工作,我只获得第一行数据库,而不是其他数据库,这是我的key问题,从db获取所有行。 我尝试使用resultresult_arrayrowrow_array查询数据库,但由于某种原因,所有内容都只列出了db中的第一行。 任何帮助,将不胜感激。

要使用codeigniter Active record从单独的table获取所有结果,您可以这样做

function permission() {
   $this->db->select("*");
   $this->db->from("employees_tasks");
   $this->db->where('id', 'your id');
   $query = $this->db->get();        
   return $query->result();
   // OR
   $query = $this->db->query("SELECT * from employees_tasks WHERE your condition");
   return $query->result();
}

希望它有意义

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM