Prals Prals - 2 months ago 9
PHP Question

Call to undefined method CI_DB_mysqli_result::results()

I am very new to CodeIgniter. I am getting below error. Can someone please help me out. I checked various answers on StackOverflow but none helped me.

An uncaught Exception was encountered

Type: Error

Message: Call to undefined method CI_DB_mysqli_result::results()

Filename: /Applications/XAMPP/xamppfiles/htdocs/CodeIgniter/application/controllers/Stud_controller.php

Line Number: 10

Backtrace:

File: /Applications/XAMPP/xamppfiles/htdocs/codeigniter/index.php
Line: 315
Function: require_once


Below is the controller code

<?php
Class Stud_controller extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->database();
}

public function index(){
$query = $this->db->get("stud");
$data['records'] = $query -> results();
$this->load->view('Stud_view',$data);
}
}
?>


And this is the view code

<!DOCTYPE html>
<html lang = "en">

<head>
<meta charset = "utf-8">
<title>Students Example</title>
</head>
<body>
<a href = "<?php echo base_url(); ?>
index.php/stud/add_view">Add</a>
</body>

</html>


Currently not using the data coming from controller.
Any help will be highly appreciated. Thanks in advance.

Answer

You should use something like this

$data['records'] = $query -> result_array();
Comments