Answer the question
In order to leave comments, you need to log in
How to take value from PHP object?
JSON is sent from js. stringify([2:3,4:5,6:8])
2 is the id 3 is the number.
$cartGoods = json_decode(file_get_contents('php://input'), true);
$goodsId = implode(",", array_map(
function ($e) {
return array_keys($e)[0];
},
$cartGoods
));
$goods = mysqli_query($connection, "SELECT * FROM `goods` WHERE `id` in ($goodsId)");
while ($item = mysqli_fetch_assoc($goods)) {
foreach ($cartGoods as $obj) {
$count = $obj[$item['id']];
}
echo $count;
}
?>
Answer the question
In order to leave comments, you need to log in
Personally, I am stopped from answering by the abundance of code that cannot be reproduced without your database and input data.
I advise you to isolate the problematic section of the code and leave only it in the question, and so that you can run it and observe the result that confuses you with your own eyes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question