Postingan lainnya
Undefined variable dan Column cannot be null pada codeigniter
Bantuanya temen", aku yang masih newbie banget ada tugas suruh perbaikin web, baru pertama pake CI, udah lari kesana kemari belom dapet jawabannya hehe.
-Controller
function konfirmasi($id,$jumlah){
if($this->session->userdata("username") == null) redirect("login/index");
date_default_timezone_set("Asia/Jakarta");
$time = Date('Y-m-d');
$where = array(
'id_topup' => $id,
);
$user = $this->m_customer->getUser("saldo_topup",$where)->row();
$view['saldo'] = $this->m_customer->get_saldoAkhir($user->id_user);
foreach($view['saldo']->result_array() as $row){
$kartu = $row['id_kartu'];
$saldo= $row['saldo'];
}
$info = array(
'id_kartu' => $kartu,
'saldo_awal' => $saldo,
'saldo_up' => $jumlah,
'saldo_akhir' => $saldo + $jumlah,
'keterangan' => 'TOPUP SALDO',
'date' => $time
);
$this->m_customer->update_saldo($kartu,$jumlah,$id);
$this->db->insert('kartu_history', $info);
redirect('customer/saldo');
}
-Model
function getUser($table,$id){
return $this->db->get_where($table,$id);
}
function get_saldo(){
$query=$this->db->query("select username,nama_customer,tgl_topup,jumlah, s.status, ket, bank, bukti, id_topup from saldo_topup s join user u on u.id_user=s.id_user");
return $query;
}
function get_saldoAkhir($id){
$query=$this->db->query("select * from kartu where id_user = $id");
return $query;
}
- Errornya
0
2 Jawaban:
apakah id_kartu diseting auto increment?
coba ganti: foreach($view['saldo']->result_array() as $row){ $kartu = $row['id_kartu']; $saldo= $row['saldo']; }
menjadi: foreach($view['saldo']->result() as $row){ $kartu = $row['id_kartu']; $saldo = $row['saldo_awal']; }
*catatan: definisikan variabel($) kartu & saldo, sama seperti variabel($time, $where) yang sudah kamu definisikan terlebih dahulu.
0
Coba di die dump variable rownya, ada isinya ngga
0