How to search data from mysql database in codeigniter.


Posted on 2018-10-12 23:38:50

Download Source Code / File

This is the easiest way to search data from mysql database in codeigniter. If you need to download the source code click on the Download button



***view***

<table border='1'>
                <thead>
                <th>name</th>
                <th>email</th>
                <th>telephone</th>
                </thead>
                <tbody>
                    <?php
                    foreach ($user as $value) {
                        ?>
                        <tr>
                            <td><?= $value['name'] ?></td>
                            <td><?= $value['email'] ?></td>
                            <td><?= $value['tp'] ?></td>
                        </tr>
                        <?php
                    }
                    ?>
                </tbody>
</table>


***controller***

class admin extends ci_controller {

    function __construct() {
        parent::__construct();
    }

    public function load_data() {
        
        $this->load->model('admin_model');
        $data['user']=$this->admin_model->getuser();        
        $this->load->view('user_results',$data);
    }   

}


***model***

class admin_model extends ci_model {

    public function __construct() {
        parent::__construct();
    }

    function getuser() {

//        $this->db->where('name', 'adam');
        $query = $this->db->get('user');
        return $query->result_array();  
        
    }    

}

                    

Leave a Comment:
Saranga Kumari2018-10-19 08:08:09
thank you.

Search
Latest Articles