1

Im trying to populate 3 tables in the view by passing 3 different arrays from the controller to the view (which get data from the database). But I get an error as

Fatal error: Call to undefined method stdClass::result_array() in C:\xampp\htdocs\SEP\application\views\ManagerViewProjectDatabase.php on line 39

The controller method is as

function ManagerProjects()
{
    $this->load->model('ViewProjectsModel');
    $new=$this->ViewProjectsModel->ManagerViewProjects('new');
    $ongoing=$this->ViewProjectsModel->ManagerViewProjects('inprogress');
    $completed=$this->ViewProjectsModel->ManagerViewProjects('completed');
    $data=array('new'=>$new, 'inprogress'=> $ongoing,'completed'=>$completed);
    $this->username=$this->session->userdata('username');
    $this->DashBoardMainView($this->username);
    $this->load->view('ManagerViewProjectDatabase',$data);
}

the model class function is as

function ManagerViewProjects($status)
{
    $this->db->select('*');
    $this->db->from('project');
    $this->db->where('status',$status);
    $query=$this->db->get();
    $q1=$query->row();
    return $q1;
}

and the view is as

                    <tbody>
                    <?php foreach ($new->result_array() as $row): ?>
                        <tr>
                            <td><?php echo $row['project_id'];?></td>
                            <td><?php echo $row['name'];?></td>
                            <td><?php echo $row['start_date'];?></td>
                            <td><?php echo $row['deadline'];?></td>
                            <td><?php echo $row['description'];?></td>
                            <td><?php echo $row['language'];?></td>
                            <td><?php echo $row['framework'];?></td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>

ManagerViewProjectDatabase Line 39 is the beginning of the foreach.

Im new to code igniter so Im not sure what goes on here with the error. Please point me in the right direction. Thanks in advance

3 Answers 3

4

Problem at Your Modal. model class function is as

So change Your model code Like this

function ManagerViewProjects($status)
{
$this->db->select('*');
$this->db->from('project');
$this->db->where('status',$status);
$query=$this->db->get();
return $query;
}

Your code results convert to row and return so only one result return.

so you return $query Variable for all results return .

This code useful for you

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

2 Comments

Thank you for your quick and correct reply. It worked for me.
@AchalaWeerasooriya if worked then you should accept answer
0

Use result_array() in your model page:

Change your codes as follows:

model:

$this->db->select('*');
$this->db->from('project');
$this->db->where('status',$status);
$q1=$this->db->get()->result_array();
return $q1;

Controller:

function ManagerProjects()
{
   $this->load->model('ViewProjectsModel');
   $new=$this->ViewProjectsModel->ManagerViewProjects('new');
   $ongoing=$this->ViewProjectsModel->ManagerViewProjects('inprogress');
   $completed=$this->ViewProjectsModel->ManagerViewProjects('completed');
   $data['result']=array('new'=>$new, 'inprogress'=> $ongoing,'completed'=>$completed);
   $this->username=$this->session->userdata('username');
   $this->DashBoardMainView($this->username);
   $this->load->view('ManagerViewProjectDatabase',$data);
}

View:

  <tbody>
     <?php foreach ($result as $key=>$value): ?>
      <tr>
      <td><?php echo $value['project_id'];?></td>
      <td><?php echo $value['name'];?></td>
      <td><?php echo $value['start_date'];?></td>
      <td><?php echo $value['deadline'];?></td>
      <td><?php echo $value['description'];?></td>
      <td><?php echo $value['language'];?></td>
      <td><?php echo $value['framework'];?></td>
      </tr>
     <?php endforeach; ?>
  </tbody>

Comments

0

also you can rewrite your model function like this:

function ManagerViewProjects($status)
{
  $this->db->where('status',$status);
  return $this->db->get('project');
}

It's becomes more compact and readable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.