gpt4 book ai didi

php - 插入有条件的多行

转载 作者:太空宇宙 更新时间:2023-11-03 11:40:29 25 4
gpt4 key购买 nike

我正在使用 foreach() 循环插入多行数据。但如果它的值为税收或折扣,我不想插入特定的行。我该怎么做。

我的代码:

<?php
if(isset($_POST['finalsave']))
{
foreach ($_POST['descr'] as $key => $descr)
{
$dept = mysql_real_escape_string($_POST['category']);
$idate = mysql_real_escape_string($_POST['idate']);
$desc1 = mysql_real_escape_string($descr);
$tags = mysql_real_escape_string($_POST['name'][$key]);
$location = mysql_real_escape_string($_POST['location'][$key]);
$war = mysql_real_escape_string($_POST['war'][$key]);
$qty = mysql_real_escape_string($_POST['qty'][$key]);
$rate = mysql_real_escape_string($_POST['rate'][$key]);
$finalamt = mysql_real_escape_string($_POST['finalamt'][$key]);

$sql2 = ("INSERT INTO `project`.`master_inventory` (`category`, `idate`, `descr`, `name`, `location`, `war`, `qty`, `rate`, `finalamt`)
VALUES ('".$dept."','".$idate."','".$desc1."','".$tags."','".$location."','".$war."','".$qty."','".$rate."','".$finalamt."')");
$sqlins = mysql_query($sql2);
//echo $sql2;
}
}
?>

最佳答案

希望对您有所帮助。

 foreach ($_POST['descr'] as $key => $descr)
{
if(($descr !="tax")||($descr !="discount"))
{
//Write your logic here
}
}

关于php - 插入有条件的多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42153377/

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