How to add template in codeigniter |how to create template in codeigniter| template in codeigniter 4
We are gave you many tutorial of codeigniter. In this tutorial I will show you how to select data from database without using Controller page.
So at first go to your view page where you show the data in a table from database. Now define a method name for go to the model page and call the method name in the model page.
Using select query in under the method name and send the array data in the view page. View the data in the table page using foreach loop.
Follow the code:
View Page :
<?php $get_data=$this->MyModel->get_table_data(); ?> <table class="table table-bordered"> <thead> <tr> <th> Name </th> <th> Email </th> <th> Phone No </th> </tr> </thead> <tbody> <?php foreach($get_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>
Model :
<?php public function get_table_data(){ $qry=$this->db->select('*')->from('Table Name')->get()->result(); return $qry; }
Related posts