Answer the question
In order to leave comments, you need to log in
Why does the answer come randomly from the database?
$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)) {
...
}
Answer the question
In order to leave comments, you need to log in
mysqli_query($connection, "SELECT * FROM `goods` WHERE `id` IN ($goodsId) ORDER BY FIELD(`id`,$goodsId)
The order (order by) is not defined, and it is more convenient for the DBMS server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question