Randika Perera Randika Perera - 1 year ago 83
PHP Question

print database data with model function codeigniter

i'am new to codeigniter and i am using following cord to print database data, but it is not working..no php error only HTTP ERROR 500.

user1.php controller file-

class User1 extends CI_Controller {

public function index()

$name = $this->user1->getUser("RANDIKA");

$this->load->view('users', $name);

user.php model file

class User1 extends CI_Model {

public function getUser($name){

$sql = "SELECT * FROM `user`";
$data['query_sql'] = $this->db->query($sql);

return $data['query_sql'];


users.php view file


Answer Source

Model Code

class User1_model extends CI_Model 
    public function getUser($name)
       $query = "SELECT * FROM `user`";
       $data = $this->db->->query($query);
       return  $data->result_array();//for single user for all return result_array() and comment $this->db->where line

Controller Code

class User1 extends CI_Controller 
    public function index()

        $data['name'] = $this->user1_model->getUser("RANDIKA");
        if($data['name'] == false )
            $data['name'] = array();            
        $this->load->view('users', $data);  

And in View

 <?php print_r($name); // will print single users details in your case its RANDIKA ?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download