Undefined property PHP error on Codeigniter

158
November 04, 2018, at 3:50 PM

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>
Answer 1

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)
Rent Charter Buses Company
READ ALSO
Getting ordered rows partly

Getting ordered rows partly

Hello developers out there,

199
Missing date in php array

Missing date in php array

I have following array:

183
Database error can not read from database [duplicate]

Database error can not read from database [duplicate]

This question already has an answer here:

158
Want to get the data of current login user in laravel using foreign key relationship but gives duplicate rows

Want to get the data of current login user in laravel using foreign key relationship but gives duplicate rows

I am trying to get the data of current login user using laravel and mysql but I am getting the result duplicate rows of stored in data baseI have three tables

133