I am trying to get to data from database details from model to controller i was not get it's saying Undefined variable: result can any one know how to get data from model to controller?
controller.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dashboard extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('login_model');
$this->load->helper(array('form', 'url'));
$this->load->library('session');
}
public function setting()
{
$this->load->database();
session_start();
$userss="";
if($_SESSION["registerid"])
{
$userss = $_SESSION["registerid"];
}
$this->load->model('setting_model');
$this->setting_model->getsetting($userss);
$data12345 = array(
'registerid' => $result[0]->registerid,
'username' => $result[1]->username,
'email' => $result[2]->email,
'password' => $result[3]->password,
'companyname' => $result[0]->companyname,
'phonenumber' => $result[0]->phonenumber ,
'address' => $result[0]->address,
'postalcode' => $result[0]->postalcode,
'descriptionofcompany' =>$result[0]->descriptionofcompany,
'creditcardinformation' =>$result[0]->creditcardinformation,
'title'=>'Setting Page'
);
//passing page title
$this->load->helper('url'); // passing base url
$this->load->view('setting',$data12345); // passing setting.php view
}
}
setting_model.php
<?php
class setting_model extends CI_Model{
function __construct() {
parent::__construct();
}
public function getsetting($userss) {
$this->load->database();
$condition = "username =" . "'" . $userss . "'";
$this->db->select('*');
$this->db->from('register');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 1) {
return $query->result();
} else {
return false;
}
}
// Read data from database to show data in admin page
}//end class
?>
Looks like you forgot to assign the query result to the $result variable. Try this $result = $this->setting_model->getsetting($userss);
in the controller.
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.