Gambar 1. Update Database -CRUD 3 -Codeigniter 3 |
Langkah Awal:
1. Config Database(dilihat halaman crud 1)2. Autoload Database (dilihat halaman crud 1)
3. Baseurl (dilihat halaman crud 2)
link halaman sebelumya:
https://komputasistat.blogspot.co.id/2016/08/insert-database-crud-2-codeigniter-3.html
https://komputasistat.blogspot.co.id/2016/08/select-database-crud-1-codeigniter-3.html
Langkah Selanjutnya:
1. database SQL:
CREATE TABLE IF NOT EXISTS `user` ( `role` int(1) NOT NULL, `id_user` int(4) NOT NULL, `username` varchar(50) NOT NULL, `password` char(128) NOT NULL, `last_login` datetime NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data untuk tabel `user` -- INSERT INTO `user` (`role`, `id_user`, `username`, `password`, `last_login`) VALUES (1, 1, 'hastan', 'C1CF6A5C0E168B080C446E7F5600B2404BA06387DC10D96014C941E5F82615AE96AA231727D38728AA446F26B6765CFDBA3E9A18F27E39B0A4B8EA2A541B4E41', '2016-08-14 00:00:00'), (2, 2, 'Oddsay', '5EBD6FB1059317FC5FBB57BB23AE6CEF10AAB311C04BEFC6D62CD3E4F7B0B6503857CF573EE84180113DF96DA1621334FDC3F691E96470637C8A4EF5B5E2A88E', '2016-08-15 00:00:00'), (3, 3, 'Oddsaydev', '18F0AE1FC46894039381FBEFCC06C4E0B0C647DD45733D4AA1756502F68942768BCABE6A2E2ECB0DC4F6456B3B1CC2B4DF54AB78EC20C8DB21A0083EEAAEEB3B', '2016-08-15 00:00:00');
2. Updatedata.php (..\application\controllers\Updatedata.php)
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Updatedata extends CI_Controller{ function __construct(){ parent::__construct(); $this->load->model('updatedata_models'); $this->load->helper( array('url' ,'form' )) ; } public function index(){ $data['user'] = $this->updatedata_models->tampil_data()->result(); $this->load->view('updatedata_forms',$data); } public function updatevalue(){ $data['user'] = $this->updatedata_models->update_data($this->input->post('id_user'))->result(); $this->load->view('updatevalue_forms',$data); } public function eksekusi(){ //echo"hallo".$this->input->post('id_user'); $data['user'] = $this->updatedata_models->eksekusi_data($this->input->post('id_user'),$this->input->post('role'),$this->input->post('username'))->result(); $this->load->view('updatedata_forms',$data); } }
3. updatedata_models.php (..\application\models\updatedata_models.php)
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Updatedata extends CI_Controller{ function __construct(){ parent::__construct(); $this->load->model('updatedata_models'); $this->load->helper( array('url' ,'form' )) ; } public function index(){ $data['user'] = $this->updatedata_models->tampil_data()->result(); $this->load->view('updatedata_forms',$data); } public function updatevalue(){ $data['user'] = $this->updatedata_models->update_data($this->input->post('id_user'))->result(); $this->load->view('updatevalue_forms',$data); } public function eksekusi(){ //echo"hallo".$this->input->post('id_user'); $data['user'] = $this->updatedata_models->eksekusi_data($this->input->post('id_user'),$this->input->post('role'),$this->input->post('username'))->result(); $this->load->view('updatedata_forms',$data); } }
4.updatedata_forms.php (..\application\views\updatedata_forms.php)
<!DOCTYPE html> <html> <head> <title>Update komputasistat.blogspot.com</title> </head> <body> <center><h1>Update</h1></center> <table style="margin:20px auto;" border="1"> <tr> <th>No</th> <th>Role</th> <th>Id User</th> <th>Username</th> <th>Password</th> <th>Last Login</th> <th>Action</th> </tr> <?php $no = 1; foreach($user as $u){ ?> <?php echo form_open('updatedata/updatevalue'); ?> <tr> <td><?php echo $no++ ?></td> <td><?php echo $u->role ?></td> <td><?php echo $u->id_user ?></td> <td><?php echo $u->username ?></td> <td><?php echo $u->password ?></td> <td><?php echo $u->last_login ?></td> <td> <?php echo form_hidden('id_user',$u->id_user); ?> <?php echo form_submit('submit', 'update'); ?> </td> </tr> <?php echo form_close(); ?> <?php } ?> </table> </body> </html>
5.updatevalue_forms.php (..\application\views\updatevalue_forms.php)
<!DOCTYPE html> <html> <head> <title>Update komputasistat.blogspot.com</title> </head> <body> <center><h1>Update Value</h1></center> <?php echo form_open('updatedata/eksekusi'); ?> <?php foreach($user as $u){ ?> id user: <?php echo $u->id_user ;?><br/> <?php echo form_hidden( 'id_user',$u->id_user ); ?> role: <?php echo form_input( 'role',$u->role ); ?><br/> username: <?php echo form_input( 'username',$u->username );?><br/> <?php echo form_submit($u->id_user, 'update'); ?> </td> <?php } ?> <?php echo form_close(); ?> </body> </html>
0 komentar:
Post a Comment