我有一张如下表:
和mysql这样的结构:
+--------+-------------------+---------+-------+----------+
| 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 |
+--------+-------------------+---------+-------+----------+
编辑:
这是我的控制器调用所有这些数据
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 as b','b.id_kec = a.nama_kec')
->join('bpbd_bpbd_bulan as c','c.id_bulan = a.bulan')
->where('a.bulan',$id_bulan)
->get('bpbd_bpbd_log_ispu as a')->result_array();
$output['id_bulan'] = $id_bulan;
$output['bulan_ganjil'] =$bulan_ganjil;
$output['data'] = $data;
//show the view
$this->view($this->cms_module_path().'/log_ispu',$output,$this->n('log_ispu'));
}
</code>
我们可以从上面的图片中看到Wilayah(&#34; Bengkalis&#34;)下面的数据 - &gt;&#39; - &#39;来自5 Desember的同一行应该与Wilayah(&#34; Bengkalis&#34;)在同一行显示,因为它来自同一个月,即Desember,但日期不同。关于如何做到这一点的任何建议?
答案 0 :(得分:0)
以下是如何实现这一目标的草图,
- &GT;首先获取所有名称结果以及primaryId
- &GT;第二次获取所有日期和名称结果以及primaryId
然后使用此日期循环
//lets assume this contains the name results with primaryId
$aNameResult;
$aData = array();
$iMonthDays = 30;
foreach($aNameResult as $aRow) {
//lets assume this contains the date based results with primaryid
$aDateResult; //$aRow['primaryId']
//first fill the available date details
foreach($aDateResult as $aDateRow){
//assign records for your daye
$aData[date('j', strtotime($aDateRow['date']))] = array();//anything you want assign it to the day
}
//fill all the remaining dates
for($i=1; $1<=$iMonthDays; $i++) {
if(!array_key_exists($i, $aData)) {
$aData[$i] = array();//assign anything you want
}
}
print_r($aData);
die();//print the per name 30 days record details
}