型号:
function insertMonths($dr){
$cus = $this->db->query("SELECT * FROM purchase WHERE status=1 AND dr_no='$dr'");
return $cus->row();
$start = (new DateTime($cus->date_sold))->modify('+1 month');
$end = (new DateTime($cust->due_date))->modify('+1 month');
$interval = DateInterval::createFromDateString('1 month');
$period = new DatePeriod($start, $interval, $end);
$query = $this->db->query("SELECT * FROM duedate WHERE dr_no='$dr'");
if($query->num_rows() > 0){
return false;
}else{
foreach ($period as $dt) {
$datas = array(
'cust_id' => $cust->cust_id ,
'mi' => $dt->format("Y-m-d") ,
'amount' => $cust->monthly_instlmnt,
'dr_no' => $dr,
'payment' => $cust->monthly_instlmnt
);
$this->db->insert('duedate', $datas);
}
}
}
控制器:
function ledger($id, $dr){
$this->load->view('layout/header');
$data['cust_data'] = $this->m->getData($id);
$datar['mos'] = $this->m->insertMonths($dr);
$this->load->view('receivables/ledger', $data, $datar);
$this->load->view('layout/footer');
}
链接到分类帐的Botton js代码:
'<td><a href="<?php echo base_url().'Receivables/ledger/';?>'+data[i].cust_id+'/'+data[i].dr_no+'"><button type="button" class="btn btn-success">View</button></a></td>'
我希望当我输入链接$datas
时,如果存在不会添加的重复数据,则将duedate
添加到表ledger/id/dr
中。
但问题是,尽管没有重复数据,但它不会添加。
答案 0 :(得分:1)
为什么你的函数的第2行有return
语句?
$cus = $this->db->query("SELECT * FROM purchase WHERE status=1 AND dr_no='$dr'");
return $cus->row();
如果你忽略了它,它就不会进入你的插入查询,因为你已经命令函数返回。
删除此功能(功能的第2行)
return $cus->row();