我有公司名称的数组插入多个MySQL记录,我插入每个公司名称作为单独record.below是代码使用阵列
<input type="text" name="company_name[]">
$company_name = $_POST['company_name'];
if($company_name)
{
foreach($company_name as $company)
{
$mycompany[] = $company;
}
}
$val="('".implode("'), ('",$mycompany)."')";
$sql = "INSERT INTO `table`
(`company_name`) VALUES ".$val."";
上面的查询看起来像这样,它成功地插入2个记录在表。
INSERT INTO `table` (`company_name`) VALUES ('DELL'), ('IBM')
现在的问题是,每COMPANY_NAME有一个company_code,我想每个记录插入和有第三值可以假设order_num这也是我想插入但order_num应该在所有记录相同,我需要以下
INSERT INTO `table` (`order_num`,`company_name`,`company_code`) VALUES ('123','DELL','axc89'), ('123','IBM','bxc90')
公司代码从哪里来? – 2012-03-03 07:43:32
以及为什么你需要公司代码和名称?不能只是代码? – 2012-03-03 07:45:32
@ Col.Shrapnel我编辑我的代码plz检查它,我做一个非常复杂的在线订单,因此我需要company_code和order_num – Arif 2012-03-03 07:48:34