Postingan lainnya
Menghitung jumlah di Codeigniter
Bantuannya temen", saya mengalami kesulitan pada saat hitung jumlah saldo. Scriptnya dibawah ini :
- Model
- Controller index )
-Controller saldo
- View list saldo
- View index
8 Jawaban:
Pada Controller index tambahkan var $saldo isinya diperoleh dari
model saldo fungsi ambil nilai saldo..lalu tambahkan $saldo ke array($data)
yg akan dikirim ke view index
krg lebih gini lah ...
<?php
$saldo = $this->M_saldo->getSaldo();
$data['title'] = "SIGN UP";
$data['saldo'] = $saldo;
$this->template->display('nama_view', $data);
?>
nanti pada view index olah $saldo.. sesuai kebutuhan bukan $row->saldo..
tapi $saldo.. tergantung return dari fungsi ambil nilai saldo agan..
cara ngolah di viewnya contohnya gimana gan ?
ya perulangan biasa yg disesuaikan dikit..tergantung return dari fungsi ambil saldonya apa ? array atau gmn..
tinggal dikondisikan dengan data yg di foreach() dari "web" klw gk salah ya..
kalau belum bisa coba code nya copy sini..soalnya kode agan gk jelas.. jgn ditaruh di image.lsg pake simbol [] aj...
Baik gan hehe
Model :
private $table="user";
private $primary="id_user";
function semua(){
$query=$this->db->query("select * from user");
return $query;
}
function saldo_customer(){
$query=$this->db->query("select * from saldo_topup");
}
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;
}
- Controller index
function index($offset=0,$order_column='id',$order_type='desc'){
if($this->session->userdata("username") == null)
{
redirect("login/index");
}
else
{
$data['username']=$this->session->userdata("username");
}
if(empty($offset)) $offset=0;
if(empty($order_column)) $order_column='id';
if(empty($order_type)) $order_type='desc';
//load data
$data['web']=$this->m_customer->semua()->result();
$data['title']="Sign Up";
$config['base_url']=site_url('customer/index/');
$config['total_rows']=$this->m_customer->jumlah();
if($this->uri->segment(3)=="delete_success")
$data['message']="<div class='alert alert-success'>Deleted Successfully!</div>";
else if($this->uri->segment(3)=="add_success")
$data['message']="<div class='alert alert-success'>Inserted Successfully</div>";
else
$data['message']='';
$this->template->display('customer/index',$data);
}
-Controller saldo
function saldo(){
if($this->session->userdata("username") == null)
{
redirect("login/index");
}
else
{
$data['username']=$this->session->userdata("username");
}
$data['web'] = $this->m_customer->get_saldo($this->session->userdata('id_outlet'))->result();
$this->template->display('customer/list_saldo',$data);
}
- View index
<?php $no=0; foreach($web as $row ): $no++;?>
<tr style="font-size:12pt">
<td><?php echo $row->id_user;?></td>
<td><?php echo $row->nama_customer;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->no_hp;?></td>
<td><?php echo $row->alamat;?></td>
<td>Rp <?php echo $row->saldo_top_up; ?></td>
<td colspan="2"><a href="<?php echo site_url('customer/edit/'.$row->id_user);?>"><i class="glyphicon glyphicon-pencil" title="Ubah"></i></a>
<a href="#" class="hapus" kode="<?php echo $row->id_user;?>"><i class="glyphicon glyphicon-remove" title="Hapus"></i></a></td>
</tr>
<?php endforeach;?>
- View list saldo
<tbody>
<?php $no=0; foreach($web as $row ): $no++;?>
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $row->username;?></td>
<td><?php echo $row->nama_customer;?></td>
<td><?php $newDate = date("d F Y", strtotime($row->tgl_topup));
echo $newDate;?></td>
<td><?php echo $row->bank;?></td>
<td>Rp <?php echo number_format($row->jumlah,0,",","."); ?></td>
<td><img id="myImg" src="http://localhost/bookonline/assets/img/bukti_pembayaran/<?php echo $row->bukti; ?>" alt="Bukti Pembayaran" width="150" height="100"></td>
<td>
<?php if($row->status == 0){ ?>
<a href="<?php echo site_url('customer/konfirmasi');?>/<?php echo $row->id_topup;?>/<?php echo $row->jumlah?>" class="btn btn-sm btn-success"><i class="glyphicon glyphicon-ok"></i> Konfirmasi Saldo</a>
<?php } else{?>
<span style="color:green" class="glyphicon glyphicon-ok"> Sudah Dikonfirmasi</span>
<?php }?></td>
</tr>
<?php endforeach;?>
</tbody>
lihat struktur table dan datanya bro... dari 2 hal yg berhubungan diatas..
lihat struktur table dan datanya gan.. kalau gk gitu susah pahamnya kan ini bukan hal umum..