Code Igniter Pertemuan 7
Code Igniter Pertemuan 7
Code Igniter Pertemuan 7
else
{echo "gagal input data";}
}
public function update()
{
$res=$this->Model_mhs1->UpdateData('mahasiswa',array(
"alamat"=>"Yogyakarta",
),array('nim'=>"11111"));
if($res>=1){
echo"update sukses";
}else{
echo"update data gagal";}
}
public function delete(){
$res=$this->Model_mhs1->DeleteData('mahasiswa',array(
'nim'=>"11111"));
if($res>=1){
echo"delete sukses";
}else{
echo"delete data gagal";
}
}
}
========================================================================
}
public function do_delete($nim){
// echo"delete nim:",$nim ;
$where=array('nim'=>$nim);
$res=$this->Model_mhs1->DeleteData('mahasiswa',$where);
$data=$this->Model_mhs1->GetMahasiswa();
$this->load->view('tabel',array('data'=>$data));
}
public function do_update(){
// echo "<pre>";
// print_r($_POST);
// echo "</pre>";
$nim=$_POST['nim'];
$nama=$_POST['nama'];
$alamat=$_POST['alamat'];
$data_update=array(
'nama'=>$nama,
'alamat'=>$alamat
);
$where=array('nim'=>$nim);
$res= $this->Model_mhs1->UpdateData('mahasiswa',$data_update,$where);
if ($res>=1){
redirect('mhs2/index');
//$data=$this->Model_mhs1->GetMahasiswa();
// $this->load->view('tabel',array('data'=>$data));
}else{
echo "update gagal";
}
}
public function edit_data($nim){
$mhs =$this->Model_mhs1->GetMahasiswa("where nim=,'$nim'");
$data=array(
"nim"=>$mhs[0]['nim'],
"nama"=>$mhs[0]['nama'],
"alamat"=>$mhs[0]['alamat'],
);
$this->load->view('form_edit',$data);
}
}
Buat file di dalam view dengan nama table.php
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Title here!</title>
</head>
<body>
<table border="1">
<tr style="background:gray;">
<th>No Induk</th>
<th>Nama</th>
<th>Alamat</th>
<th>Action</th>
</tr>
<tr>
<td>Nama</td><td><input type="text" name="nama"/></td>
</tr>
<tr>
<td>alamat</td><td><textarea name="alamat"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="simpan"value="Simpan"/></td>
</tr>
</table>
</body>
</html>
<tr>
<td>Nama</td><td><input type="text" name="nama" value='<?php echo $nama;?
>'/></td>
</tr>
<tr>
<td>alamat</td><td><textarea name="alamat"><?php echo $alamat ?></textarea></td>
</tr>
<tr>
<td><input type="submit" name="simpan"value="Simpan"/></td>
</tr>
</table>
</body>
</html>
Jalankan
http://localhost/latihan1/index.php/mhs2/index