Select records from MySQL table and print the data in a table page using jQuery in Codeigniter web application. After submit data into database, you display submit data in a table without page reload in your web browser.
PHP codeigniter is the easy and simple framework, you can use in your LocalServer or web hosting. In this tutorial you can Display insert value after submit records and stop page reload.
In this tutorial I will help you with source code and with an example. Follow the example.
Script:
<script type="text/javascript"> $.ajax({ type: 'post', url: '<?php echo base_url("Controller/select_data");?>', data: {}, success: function(result){ jQuery('#userdata').html(result); // #userdata is the table tbody Id name!! console.log(result); } }); </script>
Controller:
<?php public function select_data(){ $data=$this->MyModel->selecUserData(); $view = ''; foreach ($data as $udata) { $view = $view ."<tr>"; $view = $view ."<td>".$udata->name."</td>"; $view = $view ."<td>".$udata->email."</td>"; $view = $view ."<td>".$udata->phone."</td>"; $view = $view ."</tr>"; } echo $view; } ?>
Model:
<?php public function selecUserData(){ $qry=$this->db->select('*')->from('Table Name')->get()->result(); return $qry; } ?>
Related posts