Postingan lainnya
Buku Ini Koding!
Baru!
Buku ini akan jadi teman perjalanan kamu belajar sampai dapat kerjaan di dunia programming!
Export data per periode dengan codeigniter
Bantuannya temen", saya ingin export data ke excel per periode sesuai yang user tentukan.
- model
function toExcelAll() {
$this->db->select("id_pembelian,tgl_pembelian, total_pembelian");
$this->db->from("hpembelian");
$getData = $this->db->get();
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
- controller
function toExcelAll() {
$query['data1'] = $this->m_laporanpembelian->ToExcelAll();
$this->load->view('laporanpembelian/excel',$query);
}
- view
<form class="navbar-form navbar-left" role="search" action="<?php echo site_url('laporanpembelian/cari');?>" method="post">
<div class="form-group">
<label>Tanggal Awal :</label>
<input type="date" class="form-control" placeholder="Search" name="cari">
<label>Tanggal Akhir :</label>
<input type="date" class="form-control" placeholder="Search" name="cari2">
</div>
<button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i> Cari</button>
</form>
<div class="absolute">
<a href='<?php echo site_url('laporanpembelian/toExcelAll'); ?>' class="btn btn-primary"><i class="glyphicon glyphicon-download-alt"
aria-hidden="true">
</i>Cetak Laporan</a>
</div>
scriptnya harus dirubah bagaimana ya hehe, saya baru bisa buat export semua data
5 Jawaban:
Model
function toExcelAll() {
$this->db->select("id_pembelian,tgl_pembelian, total_pembelian");
$this->db->from("hpembelian");
$this->db->where('tanggal_awal', $this->input->post('cari')); //Nama table nya saya asumsikan tanggal_awal yaa gan hehe
$this->db->where('tanggal_akhir', $this->input->post('cari2'));
$getData = $this->db->get();
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
Lainnya tidak perlu di rubah gan ^^
tapi datanya kog ga bisa keluar ya saat di export hehe diambil dari nama table "tgl_pembelian", cuma 1 tabel ga ada tgl awal dan akhir.
function toExcelAll() {
$this->db->select("id_pembelian,tgl_pembelian, total_pembelian");
$this->db->from("hpembelian");
$this->db->where('tgl_pembelian', $this->input->post('cari')); //Nama table nya saya asumsikan tanggal_awal yaa gan hehe
$this->db->where('tgl_pembelian', $this->input->post('cari2'));
$getData = $this->db->get();
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
Oh agan mau ambil dari satu tabel yaa, kirain dari 2 tabel hehe
function toExcelAll() {
$this->db->select("id_pembelian,tgl_pembelian, total_pembelian");
$this->db->from("hpembelian");
$this->db->where('tgl_pembelian >=', $this->input->post('cari')); //Nama table nya saya asumsikan tanggal_awal yaa gan hehe
$this->db->where('tgl_pembelian <=', $this->input->post('cari2'));
$getData = $this->db->get();
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
datanya ga muncul gan hehe, masih belom bisa, udah nyari kemana-mana masih belom bisa hehe
Controller cari nya gimana gan
itu yg di view pas di
action="<?php echo site_url('laporanpembelian/cari');?>"
'Cari' controllernya kek mana gan ?
Kalau itu agan ganti jadi
action="<?php echo site_url('laporanpembelian/toExcelAll');?>"
Keluar datanya gan ^^
Tanggapan
bisa minta source code export ke excel nya