php + mysql 批量删除旧数据,插入新数据
$temp="";$addtime=time();$sql="INSERTINTO`#@__tx_rebate`(`num_iid`,`price`,`rebate`,`...
$temp = "";
$addtime = time();
$sql = "INSERT INTO `#@__tx_rebate` (`num_iid`, `price`, `rebate`, `addtime`) VALUES ";
foreach ($list as $k => $v) {
$temp[$k] = "({$v[$fields]},'{$v['price']}','{$v['coupon_price']}','{$addtime}')";
;
}
$sql .= implode(",",$temp) . ';';
echo $sql;
html 输出
INSERT INTO `#@__tx_rebate` (`num_iid`, `price`, `rebate`, `addtime`) VALUES (17472695050,'228.00','114.00','1369291635'),(10241944710,'59.00','25.00','1369291635'),(21811980934,'108.00','75.60','1369291635');
问 :如果数据库中已经有num_iid 为17472695050 时,怎么做到 删除原来的数据,并插入最新的数据
备注,sql 不能写到循环中、 展开
$addtime = time();
$sql = "INSERT INTO `#@__tx_rebate` (`num_iid`, `price`, `rebate`, `addtime`) VALUES ";
foreach ($list as $k => $v) {
$temp[$k] = "({$v[$fields]},'{$v['price']}','{$v['coupon_price']}','{$addtime}')";
;
}
$sql .= implode(",",$temp) . ';';
echo $sql;
html 输出
INSERT INTO `#@__tx_rebate` (`num_iid`, `price`, `rebate`, `addtime`) VALUES (17472695050,'228.00','114.00','1369291635'),(10241944710,'59.00','25.00','1369291635'),(21811980934,'108.00','75.60','1369291635');
问 :如果数据库中已经有num_iid 为17472695050 时,怎么做到 删除原来的数据,并插入最新的数据
备注,sql 不能写到循环中、 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询