Php 基于多个复选框和输入更新数据库中的多行
我有下面的数组,我需要根据这个更新数据库。 它应该类似于下面的示例代码,但我不知道如何正确执行:Php 基于多个复选框和输入更新数据库中的多行,php,mysql,Php,Mysql,我有下面的数组,我需要根据这个更新数据库。 它应该类似于下面的示例代码,但我不知道如何正确执行: UPDATE productPercent SET percent="$percent" WHERE store="$store" AND startDate>"$start_date" AND endDate<"$end_date" AND storeGroup="$storeGroup" AND productGroup="$product_group" AND prod
UPDATE productPercent SET percent="$percent" WHERE
store="$store" AND
startDate>"$start_date" AND
endDate<"$end_date" AND
storeGroup="$storeGroup" AND
productGroup="$product_group" AND
productName LIKE '$search%'
更新:数据模型-表名:列(连接的表)
存储:id、名称、开始日期、结束日期storeGroup:id,storeGroupID(在表storeGroupName:id,name中),storeID
productGroup:id,productID(在表productName:id,name中),groupID(在表productGroupName:id,name中)
productName:id、名称
productPercent:id、productID、storeID、percent您能提供您的数据模型吗?谢谢。我有几个问题,因为我不太熟悉pdo。第一行代码代表什么?因为我在不在对象上下文中时使用$this,并且与以下行混淆:
productGroup.id=storeGroup.groupID上的内部联接productGroup,因为storeGroup没有groupID
Array
(
[percent] => 3
[store] => Array
(
[0] => 36
[1] => 45
[2] => 56
)
[start_date] => 2015-02-09
[end_date] => 2015-03-31
[storeGroup] => Array
(
[0] => 2
[1] => 4
)
[product_group] => Array
(
[0] => 13
[1] => 31
[2] => 32
)
[search] => iphone
[setPercent] => Submit
)
$pdoHandle = $this->getPDOHandle();
$searchword = 'iphone';
$sql = "UPDATE
productPercent
inner join store on productPercent.storeID=store.id
inner join storeGroup on storeGroup.storeID=store.id
inner join productGroup on productGroup.id=storeGroup.groupID
inner join productName on productPercent.productID=productName.id and productGroup.productID=productName.id
SET percent=:percent
WHERE productName.name like :searchword";
$pdo->prepare($sql);
$pdo->setAttribute('percent', floatval($percent/100));
$pdo->setAttribute('searchword', $searchword . '%');