How to insert complete array into mysql, only last row is inserted

$itm_detail=$_POST[‘itm_detail’];
$t9=explode(",",$itm_detail);

//Loop through the array
for($i = 0, $c = count($t9); $i < $c; $i += 3) {
echo $t9[$i]. ‘
’.$t9[$i+1]. ‘
’.$t9[$i+2]. ‘
’;

// Insert a row of information into the table “order_item”
$sql_3="INSERT INTO order_item (Order_No, Itm_Code, Itm_Desc, Itm_Qty)

VALUES (’$_POST[t1]’, ‘{$t9[$i]}’, ‘{$t9[$i + 1]}’, ‘{$t9[$i + 2]}’)";

// Add a comma if this is not the last batch
if($i + 3 < $c) {
$sql_3 .= ", ";
}
}

mysql_query($sql_3,$con);

[php]$itm_detail=$_POST[‘itm_detail’];
$t9=explode(",",$itm_detail);

//Loop through the array
for($i = 0, $c = count($t9); $i < $c; $i += 3) {
echo $t9[$i]. ‘
’.$t9[$i+1]. ‘
’.$t9[$i+2]. ‘
’;

// Insert a row of information into the table “order_item”
$sql_3="INSERT INTO order_item (Order_No, Itm_Code, Itm_Desc, Itm_Qty)

VALUES (’$_POST[t1]’, ‘{$t9[$i]}’, ‘{$t9[$i + 1]}’, ‘{$t9[$i + 2]}’)";
mysql_query($sql_3,$con);
}
[/php]

Or if you like with only one mysql_query you can’t repeat the fields
[php]
//Loop through the array
$sql_3="INSERT INTO order_item (Order_No, Itm_Code, Itm_Desc, Itm_Qty) VALUES ";
for($i = 0, $c = count($t9); $i < $c; $i += 3) {
echo $t9[$i]. ‘
’.$t9[$i+1]. ‘
’.$t9[$i+2]. ‘
’;

// Insert a row of information into the table “order_item”

$sqll_3.=" (’$_POST[t1]’, ‘{$t9[$i]}’, ‘{$t9[$i + 1]}’, ‘{$t9[$i + 2]}’)";

// Add a comma if this is not the last batch
if($i + 3 < $c) {
$sql_3 .= ", ";
}
}

mysql_query($sql_3,$con);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service