我的数据库
这是我的数据库“日记”
我得到了结果: Records
我的问题是我只显示了一次凭证号码和日期,它在我的结果中重复出现。 如何显示为一个。
我的 Controller 代码:
public function Journal_Print(){
$data['startdate'] =$this->input->post('SDate');
$data['enddate'] = $this->input->post('EDate');
$PName = $this->input->post('TName');
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
$this->db->where('Date >=', $newDate);
$this->db->where('Date <=', $newDate2);
$query = $this->db->get('journal');
$data['PName']=$query->result_array();
// print_r($data);
$this->load->view('BookKeeping/Journal_Print', $data, FALSE);
}
我的查看页面代码:
<?php foreach ($PName as $row): ?>
<tr>
<td><?php echo date('d/m/Y', strtotime($row['Date']));?></td>
<td>
<?php echo $row['Vno'];?></td>
<td><?php echo $row['Parti'];?></td>
<td class="price"><?php echo $row['Debit'];?></td>
<td class="price1"><?php echo $row['Credit'];?></td>
</tr>
<?php endforeach ?>
如何避免这个问题
最佳答案
此 Controller 代码
$this->db->select('*');
$this->db->distinct( );
$this->db->where('Date >=', $newDate);
$this->db->where('Date <=', $newDate2);
$result = $this->db->get('journal')->result_array();
if($result){
$finalArray = array();
$checkArray = array();
foreach ($result as $key => $value) {
if(in_array($value['Vno'], $checkArray)){
$finalArray[$value['Vno']][] = $value;
} else {
$checkArray[] = $value['Vno'];
$finalArray[$value['Vno']][] = $value;
}
}
$data['query'] = $finalArray;
我的答案图片 enter image description here
关于php - 如何避免日期和凭证号码重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54421072/