php - codeigniter view data for each month based on location and date -
i have table below :
and mysql structure :
+--------+-------------------+---------+-------+----------+ | id_log | nama_kec | tanggal | bulan |kadar_ispu| +--------+-------------------+---------+-------+----------+ | 1001 | bengkalis | 1 | 12 | 100 | | 1002 | bengkalis | 5 | 12 | 0 | | 1003 | bandar sei kijang | 1 | 12 | 10 | | 1004 | bandar petalangan | 1 | 12 | 0 | +--------+-------------------+---------+-------+----------+
edit :
here's controller call data
public function tampil($id_bulan='') { //get $id_bulan $ambil_bulan = $this->db->select('nama_bulan,id_bulan') ->get('bpbd_bpbd_bulan')->result(); $output['ambil_bulan'] = $ambil_bulan; //get data nama_kec,tanggal, bulan, kadar_ispu $data = $this->db->select('a.id_log,a.nama_kec,a.tanggal,a.bulan,a.kadar_ispu,b.nama,c.nama_bulan') ->join('bpbd_bpbd_kecamatan b','b.id_kec = a.nama_kec') ->join('bpbd_bpbd_bulan c','c.id_bulan = a.bulan') ->where('a.bulan',$id_bulan) ->get('bpbd_bpbd_log_ispu a')->result_array(); $output['id_bulan'] = $id_bulan; $output['bulan_ganjil'] =$bulan_ganjil; $output['data'] = $data; //show view $this->view($this->cms_module_path().'/log_ispu',$output,$this->n('log_ispu')); } </code>
we can see image above wilayah("bengkalis") data below ->'-' came 5 desember should shown @ same row wilayah("bengkalis") @ top since same month desember different date. advice on how this?
this big task can't explain items , codes. may how implement this,
here out sketch of how achieve this,
-> first fetch name results along primaryid
-> second fetch date , name results along primaryid
then use date loop
//lets assume contains name results primaryid $anameresult; $adata = array(); $imonthdays = 30; foreach($anameresult $arow) { //lets assume contains date based results primaryid $adateresult; //$arow['primaryid'] //first fill available date details foreach($adateresult $adaterow){ //assign records daye $adata[date('j', strtotime($adaterow['date']))] = array();//anything want assign day } //fill remaining dates for($i=1; $1<=$imonthdays; $i++) { if(!array_key_exists($i, $adata)) { $adata[$i] = array();//assign want } } print_r($adata); die();//print per name 30 days record details }
Comments
Post a Comment