【发布时间】:2019-04-09 07:22:13
【问题描述】:
我是 codeigniter 框架的新手,我正在尝试停止表中的重复记录 在我的表记录中重复我想一次显示一条记录
这是我的代码
控制器
$modelResult = $this->freightBillModel->freightBillByDate($data);
<table id="freight_table" class="table table-bordered table-striped table-sm" style="display:block; overflow: auto; ">
<tr>
<th>SR.No</th>
<th>Bill No</th>
<th>pkgs</th>
<th>freight</th>
</tr>
<tbody>
<?php $counter = 1; ?>
<?php foreach($modelResult as $freight){?>
<tr>
<td><?php echo $counter;?></td>
<td><?php echo $freight['tbb_no'];?></td>
<?php $singleBill = $this->freightBillModel->fetchBillByNo($freight['tbb_no']); ?>
<?php $lr_freight=0; $no_of_pkgs=0; ?>
<?php foreach ($singleBill as $bill) : ?>
<?php $lr_freight+=$bill->lr_freight; ?>
<?php $no_of_pkgs+=$bill->no_of_pkgs; ?>
<?php endforeach; ?>
<td><?php echo $no_of_pkgs;?></td>
<td><?php echo $lr_freight;?></td>
</tr>
<?php $counter++; ?>
<?php }?>
</tbody>
</table>
型号:
public function freightBillByDate($data){
extract($data);
$this->db->select('bn.branch_name as to,ts_tbb.tbb_no,ts_tbb.tbb_id,ts_tbb.bilty_id,ts_tbb.current_time,ts_tbb.status,b.*');
$this->db->from('ts_tbb');
$this->db->join('bilty b', 'b.id = ts_tbb.bilty_id');
$this->db->join('branch bn', 'b.lr_to=bn.branch_id');
$this->db->where('lr_from',$lr_from);
$this->db->where('lr_to',$lr_to);
if($bill_type=="pending_bill"){
$this->db->where('billed_status','not_billed');
}else if($bill_type=="bill_register"){
$this->db->where('billed_status','billed');
}
$this->db->order_by('lr_date','desc');
$query=$this->db->get();
return $query->result_array();
}
function fetchBillByNo($billNo){
return $this->db->select('*')->from('ts_tbb')->join('bilty','bilty_id=bilty.id')->where('tbb_no',$billNo)->get()->result();
}[![In this picture first two records are repeat][1]][1]
我想展示独特的记录, 当前表它显示重复的行 请告诉我我的代码哪里错了
【问题讨论】:
标签: php mysql sql codeigniter