How can a certain KEY be skipped automatically at the same time?

$subtotal = $pdo->query(
      "SELECT
        s.quan as quan,
        s.price as price,
        p.store_id as store_id
      FROM `stock` as s 
      JOIN product as p ON s.prod_id = p.prod_id "
    );
while ($row_ = mysqli_fetch_array($subtotal)){

      $subtotal_price += $row_["quan"]*$row_["price"];

      $pdo->query(
        "INSERT INTO `order_record` (
          `subtotal_price`
        )
        VALUES
        (
          "{$subtotal_price}"
        ) "
      );

      

    }

stock will have merchandise ID and quan, price, merchandise ID will not repeat.

I have a problem now!
store_id is a store ID
product noodles each item has a store_id value (will be repeated)
I want to add data to order_record
, but only if
assumes that the store_id of the product is the same
when querying (or during while tracking), then multiply quan and price into $subtotal_price, on the iteration side, and then add the number to the order_record profile
, that is, fake the store_id of the product. Just once.
how can I write this?

Mar.28,2021

you first array_count_values (), the obtained array to know which values are repeated, then multiply quan and price into $subtotal_price, and finally define a map/set outside the while loop before throwing it to order_record


. At the beginning of the
loop, determine whether set.get (store_id) exists. If it does not exist, you can skip it. If it does not exist, save key to set, and execute other logic normally

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b34727-2bef8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b34727-2bef8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?