我遇到某种网络商店的问题'我正在建设 我在数据库中添加了一些产品,但我只想在产品已存在时更改数量。
我只是不知道如何实现这一目标。有人可以帮我一个功能来检查产品是否已经存在,这样我每次添加已经存在的产品时都可以为[' aantal']添加+1?
帖子是:
if(isset($_POST['submit-bonbon'])){
$postGewicht = $_POST['gewicht'];
$bonbonName = $_POST['product'];
$image = $_POST['afbeelding'];
$quantity = $_POST['aantal'];
$jsonData = unserialize($_SESSION['json_data']);
if(count($jsonData,1) >= 1){
$jsonData['bonbons'][] = array('gewicht' => $postGewicht,'name' => $bonbonName,'afbeelding' => $image, 'aantal' => $quantity);
} else {
$bonbonsArray[] = array('gewicht' => $postGewicht,'name' => $bonbonName,'afbeelding' => $image, 'aantal' => $quantity);
$order = array('userId' => $bonbonUser, 'bonbons' => $bonbonsArray);
$jsonData = $order;
}
$_SESSION['json_data'] = serialize($jsonData);
$orderData = $_SESSION['json_data'];
$query = mysql_query("SELECT * FROM CMS_bonbonOrder WHERE userId='$bonbonUser'");
mysql_query("UPDATE CMS_bonbonOrder SET jsonData='$orderData' WHERE userId='$bonbonUser';");
}
所以我在数据库中放了一个Json字符串,例如:
Array
(
[bonbons] => Array
(
[0] => Array
(
[gewicht] => 16
[name] => test
[afbeelding] => amarena%2020g1.jpg
[aantal] => 1
)
[1] => Array
(
[gewicht] => 16
[name] => test
[afbeelding] => amarena%2020g1.jpg
[aantal] => 1
)
[2] => Array
(
[gewicht] => 16
[name] => test
[afbeelding] => amarena%2020g1.jpg
[aantal] => 1
)
[3] => Array
(
[gewicht] => 18
[name] => Testbonbon 2
[afbeelding] => bresil%2017g1.jpg
[aantal] => 1
)
[4] => Array
(
[gewicht] => 16
[name] => test
[afbeelding] => amarena%2020g1.jpg
[aantal] => 1
)
)
)
我真的希望自己足够清楚!
由于