gpt4 book ai didi

php - 如何从 Excel 中转义重复值并尝试插入到 Codeigniter 中的数据库中?

转载 作者:行者123 更新时间:2023-11-29 22:51:42 25 4
gpt4 key购买 nike

亲爱的 friend ,我使用下面的函数在 Codeigniter 中创建导入功能,但当我从 Excel 中选择循环时,当数据上发生重复值时,我不知道如何转义主键仅用于$in_val['in_no'],其他值可以随意插入。如何转义重复值并尝试将 Excel 中的其他行插入数据库?

这是我的函数

public function imported($file_paths) {
$in_val = array();
$i = 0;
$cell_array = $this->csvimport->get_array($file_paths);
foreach ($cell_array as $row) {
if ($i === 7000)break; {
$in_val['user_id'] = 70;
$in_val['in_no'] = (int) preg_replace("/(\D+\d{4})0*([1-9]+\d*)/i", "$2\n", trim($row['IN_number']));
$in_val['fi_no'] = trim($row['Fir_obtic']);
$in_val['paid_by'] = trim($row['Paid_by']);
$in_val['in_per'] = str_replace('/', '-', trim($row['In_date']));
$in_val['sale_by'] = trim($row['Sale_by']);
$in_val['billed'] = trim($row['Billed']);
$in_val['in_date'] = str_replace('/', '-', trim($row['In_date']));
$in_val['top_up_num'] = trim($row['T_P_number']);
$in_val['ffrom'] = trim(str_replace('/', '-', $row['From']));
$in_val['fto'] = str_replace('/', '-', trim($row['to']));
$in_val['pay_du_date'] = str_replace('/', '-', trim($row['Pay_due_date']));
$in_val['bill_amount'] = trim(str_replace('/', '-', $row['Bill_Amount']));
$in_val['bill_to'] = trim($row['Cust_name']); //customer name
$in_val['receiv_date'] = trim($row['R_C_date']);
$in_val['adds'] = trim($row['Address']);
$in_val['bill_item'] = str_replace('/', '-', trim($row['Bill_Item']));
$in_val['descr'] = trim($row['Description']);
$in_val['in_type'] = strtolower(preg_replace("/(\D+\d{0})0*([0-9]+\d*)/i", "$1\n", trim($row['IN_number'])));
$in_val['quant'] = trim($row['In_Quanity']);
$in_val['unit_p'] = trim($row['In_Unit_P']);
$in_val['amount'] = trim($row['Bill_Amount']);
$in_val['total'] = trim($row['Total']);
$in_val['status'] = 1;
$in_val['amc'] = trim($row['Amount_Description']);
$pri_val['user_id'] = 70;
$pri_val['type'] = strtolower(preg_replace("/(\D+\d{4})0*([1-9]+\d*)/i", "$1\n", trim($row['IN_number'])));
$pri_val['parent'] = 1;
$pri_val['status'] = 1;
$pri_val['in_no'] = (int) $in_val['in_no'];
$pri_val['total'] = (int) trim($row['Total']);
$pri_val['in_date'] = $in_val['in_date'];
$this->db->insert('dbfinan_invoice', $in_val);
$this->db->insert('prifix', $pri_val);
$i++;
}
}
}

请帮忙

最佳答案

尝试添加条件和函数来检查表,如下所示:

if($this->[yourmodal]->isExist($in_val['in_no'])==false)
{
$this->db->insert('dbfinan_invoice', $in_val);
$this->db->insert('prifix', $pri_val);
}

所以表中的 $in_val['in_no'] 可以是唯一的

关于php - 如何从 Excel 中转义重复值并尝试插入到 Codeigniter 中的数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28871939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com