php - How to insert form input field in table? -
i have displayed student's name in table format through ajax. want associate form input field each student can insert marks , store in database? how can achieve this? below code..
<script type="text/javascript"> function select_std() { var ali = $('#class_std').val(); $('#std_name').html(''); $.ajax({ url: "<?php echo base_url().'admin/test/'?>" + ali, type: "get", success: function(res) { $('#mytable tbody').append(res); } }); } </script>
and controller :
public function test($id=''){ $table='students'; $columns=array('*'); $where=array('c_id'=>$id); $data['rcd']= $this->crud->get_records($table, $columns, $where)->result(); foreach ($data['rcd'] $value) { $output = "<tr><td>".$value->name."</td><td>90</td><td>very good<td></tr>"; echo $output; } }
this table format in have showed student's names in first <td>
through ajax database. , want make second <td>
input field store marks in database.
<table cellpadding="1" cellspacing="1" id="mytable" class="table table-boardered table-responsive" id="example2"> <thead> <th width="20px;">name</th> <th>marks obtained(100)</th> <th>comments</th> </thead> <tbody id="std_name"> </tbody> </table>
you should put form on table/your loop every student has designated input field if want make action specific student id of specific student inserts db. (get(id) = idfromdb).
<?php foreach ($data['rcd'] $value) { ?> <tr><td><?php $value->name ?></td><td>90</td><td>very good<td></tr> <tr><td> <input field here> <input button value=$value[id]> </td></tr> <?php } ?>
then in next page or same page you:
<?php if(isset($_post['button name'])){ $id = $_post[button name]; insert data db $id = idfromdb }?>
ahaha sorry dude forgot php. :(
Comments
Post a Comment