2

I'm working on task manager where have 2 types of user: Administrators(all privileges), and Users(limited privileges).

Here's my task function in controller

public function task($id)
{
    $data = array(
        'query' => $this->main_model->get_task($id),
        'task_id' => $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);
        if (in_array($id, $qu[0]) && in_array($id_emp, $qu[0])) {
            $this->load->view('task', array_merge($data, $data1, $data2));
        }
    }
    // ...
}

What I'm trying to do is, get all data from database employee_tasks check if the ID_task and ID_employee are in the same row in database, but I can't get it working, I only getting first row of database, not the others, and that's my key problem, get all rows from db.

I tried query database with result, result_array, row, row_array, but for some reason everything is listing only first row in db.

5
  • employees_tasks is the your DB name or table name ?? Commented May 21, 2013 at 9:59
  • Yes, name of table with ID_task column and ID_employee column, to know what user belongs to which task Commented May 21, 2013 at 10:10
  • can you please tell me that you want all data from this table or there is any condition Commented May 21, 2013 at 10:17
  • I just need all data from database, later will be condition with php Commented May 21, 2013 at 10:20
  • can you give us your database result? Commented May 21, 2013 at 10:57

1 Answer 1

10

To get all results from a separate table using codeigniter Active record you can do like this

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

Hope it makes sense

Sign up to request clarification or add additional context in comments.

7 Comments

you don't need to use $this->db->select("*"); or $this->db->from("employees_tasks");! it is ok using that: $query = $this->db->get('employees_tasks');. read : Active Record
@rcpayan yes you are right but Dario Juric has already used this method so this can also be done in my mentioned way
dianuj thanks, but same results, when printing your metod in controller I get this: Array ( [0] => stdClass Object ( [ID_employee] => 2 [ID_task] => 42 ) ) only the first row, but there's three of them
run query in phpmyadmin and see you are getting all results
All three rows is listed without problems when run your query in phpmyadmin
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.