0
How to insert more than one row from data gotten from mysqli_fetch_array?
I have two tables, store and order. I want to select all rows from store and insert some columns in order. I have tried to use while loop but only one row is inserted and another is left.
2 Respostas
0
do you use a join (left or right) for your sql query?
the result should be an array. do you proof if the array has only 1 result?
otherwise please let us see your writen code
example for mysqli_fetch_array http://php.net/manual/de/mysqli-result.fetch-array.php
or
https://www.w3schools.com/php/func_mysqli_fetch_array.asp
0
My codes below insert two rows into orders_product but with the same values, I was expecting to insert two rows with different values from cartstore. Please help me.
$sqlResult = "SELECT * FROM cartstore";
$resultOrder = mysqli_query($dbconnect, $sqlResult);
$count = mysqli_num_rows($resultOrder);
while ($row = mysqli_fetch_array($resultOrder)) {
for ($i=$count; $i >0 ; $i--) {
$getProductId = $row["productId"];
$getQuantity = $row["quantity"];
$sqlResult = "INSERT INTO orders_products(order_id, product_id, order_procuct_quantity) VALUES('$orderId', '$getProductId', '$getQuantity')";
$resultOrder = mysqli_query($dbconnect, $sqlResult);
}
}