In this tutorial I will show you how to select data from MYSQL table and fetch in your table view page. I will provide source code with an example and this tutorial I will sho simple and easy process.
In codeigniter when you work with MySQL table then you need to connect database in your web application. Connect database follow the step:
1) Open your project folder,
2) Click application folder and open it,
3) Choose config folder and open it,
4) Look database.php and open this file in a text editor,
5) Set database connection, like that –
Now you create a table page where you fetch selected data from MySQL table. View the table page using controller function and create a array variable and go to model page define a method in controller page.
In model page select all records from MySQL table and return in the table view page. The records fetch in table page using foreach() loop.
Example and Source code:
Table page:
<table class="table table-bordered table-hover" id="sample-table-1"> <thead> <tr> <th>Name</th> <th>Email</th> <th> Phone </th> </tr> </thead> <tbody> <?php foreach($table_data as $val){ ?> <tr> <td><?php echo $val->name; ?></td> <td><?php echo $val->email; ?></td> <td><?php echo $val->phone; ?></td> </tr> <?php } ?> </tbody> </table>
Controller:
<?php public function get_table_data(){ $data['table_data']=$this->Model->getTableData(); $this->load->view('my_table',$data); } ?>
Model:
<?php function getTableData(){ $this->db->from('Table Name'); $sec_qry=$this->db->get(); return $table_data=$sec_qry->result(); }
Do you wants Make money online with blogging so contact us. I will help you data recovery service los angeles. I think it will be helpful for you.