How to insert more than one row from data gotten from mysqli_fetch_array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

27th May 2017, 6:21 AM
Joas Dioniz
Joas Dioniz - avatar
2 Answers
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
27th May 2017, 6:39 AM
Oliver
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); } }
29th May 2017, 11:33 AM
Joas Dioniz
Joas Dioniz - avatar