Postingan lainnya
Buku Ini Koding!
Baru!
Buku ini akan jadi teman perjalanan kamu belajar sampai dapat kerjaan di dunia programming!
Hapus data dengan codeigniter gagal
kenapa saat klik tombol delete, data tidak terhapus tetapi id url bisa terbaca http://localhost/pendataan-perpus/admin/dataperpus/hapus_data/3
// MODELS
public function hapus_data($where, $table)
{
$this->db->where('fileperpus', $where);
$this->db->delete($table);
}
//CONTROLLERS
public function hapus_data($id_data)
{
$where = array('id_data' => $id_data);
$this->m_perpustakaan->hapus_data($where, 'fileperpus');
redirect('admin/dataperpus');
}
// VIEW
$id_data = 1;
foreach ($dataperpus as $dp) : ?>
<tr>
<td><center><?php echo $id_data++ ?></center></td>
<td><?php echo $dp->nama_kecamatan ?></td>
<td><?php echo $dp->nama_desa ?></td>
<td><?php echo $dp->nama_perpus ?></td>
<td onclick="javascript: return confirm('Anda yakin hapus ?')"><?php echo anchor('admin/dataperpus/hapus_data/' . $dp->id_data, '<center><div class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></div></center>') ?></td>
2 Jawaban:
<pre> $where //coba ganti jangan array di controller </pre>
query builder utk delete data di Codeigniter dengan kondisi tertentu
<pre> $this->db->where('nama_kolom', 'data')->delete('nama_tabel'); </pre>
coba di Controller dirubah seperti ini
<pre> public function hapus_data($id_data) { $this->m_perpustakaan->hapus_data($id_data, 'fileperpus'); redirect('admin/dataperpus'); } </pre>
kemudian di model
<pre> public function hapus_data($id_data, $table) { $this->db->where('id_data', $id_data); $this->db->delete($table); } </pre>
CMIIW