是否可以在这样的表格视图中显示数据?
我只能在约会时向您展示,当在另一个日期检索数据时,id_status一切都无效。
控制器只有一个日期。
public function status()
{
$tanggal1 = '2017-03-28';
$data['status'] = $this->M_Reports->status($tanggal1);
$this->load->view('homepage/template');
$this->load->view('report/status', $data);
}
模特:
public function status($tanggal1) {
$sql = "SELECT operasional.id_ops, operasional.id_status, operasional.tanggal, peralatan.nm_peralatan FROM operasional INNER JOIN peralatan ON operasional.id_peralatan = peralatan.id_peralatan WHERE tanggal='$tanggal1' ORDER BY id_ops";
return $this->db->query($sql)->result();
}
并查看:
<?php
$start = 0;
foreach($status as $data) {
?>
<tr>
<td><?php echo ++$start ?> </td>
<td><?php echo $data->nm_peralatan ?></td>
<td><?php echo $data->id_status ?></td>
<td><?php echo $data->tanggal ?></td>
</tr>
<?php
}
?>
答案 0 :(得分:0)
你的模型功能应该是这样的
public function status($top_of_date)
{
// This will get all dates
$dates=$this->db->distinct()->select('tanggal')->from('operasional')->get()->result_array();
// This will get all patients / peralatan
$patients=$this->db->distinct()->select('id_peralatan')->from('operasional')->get()->result_array();
// Loop through peralatan
for($i=0;$i<count($patients);$i++)
{
$st=$this->select('id_peralatan')->from('operasional')->WHERE('id_peralatan',$patients[$i])->get()->result_array();
// Start Creating an array for this index
$data[$i]=array(
'id_peralatan'=>$st[0]
);
// loop through dates
for($j=0;$j<count($dates);$j++)
{
//if date is greater than top of date
if($dates[$i]>$top_of_date)
{
$st=$this->db->select('id_status')->from('operasional')->WHERE('tanggal',$dates[$i])->get()->result_array();
// Create index and save the status
$data[$i]['top_of_date']=$st[0]['id_status'];
}
elseif($dates[$i]<$top_of_date)
{
$st=$this->db->select('id_status')->from('operasional')->WHERE('tanggal',$dates[$i])->get()->result_array();
// Create index and save the status
$data[$i][$dates[$i]]=$st[0]['id_status'];
}
}
}
return $data;
}
现在从你的控制器你只需要发送最新的日期。等;
public function status()
{
$tanggal_top = '2017-03-28';
$data['status'] = $this->M_Reports->status($tanggal_top);
$this->load->view('homepage/template');
$this->load->view('report/status', $data);
}