0

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.

enter image description here

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>
2
  • $row is not what you think it is, It's not a result row, its your Mysqli instance, so trying to access z_id a property which does not exist in class Mysqli, gives you the error. At least that is what that error message means. You need to fetch the data instead of iterating with foreach. Commented Nov 3, 2018 at 14:39
  • while ($row = $get_ztable->fetch_object()) Commented Nov 3, 2018 at 15:34

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

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.