简体   繁体   中英

Undefined property PHP error on Codeigniter

I am super stuck on a problem. I went through many solution give here related to this but I did not found any solution to my error.

this is the error message I am facing and I used print_r to view what is the output but is also a dead end.

在此处输入图片说明

My controller - Search.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Search extends CI_Controller {

    function index(){
        $this->load->model("ModSearch");
        $data["get_ztable"] = $this->ModSearch->get_zscore();       
        $data["get_course"] = $this->ModSearch->getCourse();
        $data["get_stream"] = $this->ModSearch->getStream();    
        $data["get_district"] = $this->ModSearch->getDistrict();
        $data["get_uni"] = $this->ModSearch->getUniversity();       
        $this->load->view('addZscore',$data);

    }

Model - ModSearch.php

public function get_zscore(){       
        $query = $this->db->get('tbl_zscore');
        return $query;
    }   

View - addZscore.php

<table style="width:50%">
   <tr>
      <th>Z ID</th>
      <th>Z Score</th>
   </tr>
   <?php echo print_r($get_ztable);?>
   <?php
      if($get_ztable->num_rows() > 0)
      {
      foreach ($get_ztable as $row)
      {
      ?>
   <tr>
      <td><?php echo $row->z_id; ?></td>
      <td><?php echo $row->z_score; ?></td>
   </tr>
   <?php
      }
       }else{
      echo 'Database Error(' . $this->db->_error_number() . ') - ' . $this->db->_error_message();
       }
       ?>
</table>

You have to make changes in your model function that must return a "result" that you can easily use in your view. So just replace

return $query

with

return $query->result()

Or make a change in your foreach loop in views from

foreach($get_ztable as $row)

to

foreach($get_ztable->result() as $row)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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