Link to home
Start Free TrialLog in
Avatar of nish darsh
nish darsh

asked on

A PHP Error was encountered Severity: Notice Message: Undefined variable: persona

I am getting the above error and I am really not sure where I am going wrong. I am using Codeigniter framework. Following is my code:

Controller:

public function createtask()
      {
      
  $this->load->model('persona_model');
    $data['persona']=$this->persona_model->view();
                  $this->load->view('createtask_view', $data);
            }

Model:

function view()
      {
          $this->db->select('*');
          $this->db->from('persona');
          $query = $this->db->get();
          if($query->num_rows()>0){
          return $query->result();
          }else{
              return $query->result();
          }
      }


view:
                <table class="table">
                <thead>
              <tr>
                <th>Persona ID </th>
                <th>Firstname </th>
                <th>Lastname</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                  foreach($persona as $row)
                {
                      ?>
                      <tr>
                      <td><?php echo $row->personaid; ?></td>
                      <td><?php echo $row->firstname; ?></td>
                      <td><?php echo $row->lastname; ?></td>
                  <?php      }
                  ?>
                   </tbody>


Kindly help I have been looking into this since a long time.
SOLUTION
Avatar of Radek Baranowski
Radek Baranowski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nish Darsh
Nish Darsh

Thank you very much.. both you comments helped me retireve the values from database and display it..