Here I'm trying to insert the datas again into database new table (with quantity & customer details). $grocery_id and $grocery_item values are fetch from database. $customername, $customermobile, $groqty values are user will enter the details in that appropriate textfield.
When I execute this code ($groceryid, $groceryitem) -> These two column always stored the last row values. Because I've put the query outside of foreach loop. Here is my problem. If I put the query inside the foreach it works fine. But, quantity values doesn't work properly. So, How can I execute the query properly (outside of foreach loop)?
<?php
    if(isset($_POST['submit']))
    {
        $grocery_id = $rowid;
        $grocery_item = $rowsitem;
        $customername = $_POST['customername'];
        $customermobile = $_POST['customermobile'];
        $groqty = $_POST['groceryquantity'];
        for($i = 0; $i < sizeof($groqty); $i++)
        {
            $groqtys = $groqty[$i];
            foreach($grocery_id as $key => $index_id )
            {           
            }       
            $sql = "INSERT INTO ".customer_order." SET grocery_id = '$index_id' , grocery_item = '$grocery_item[$key]', customername = '$customername', customermobile = '$customermobile', quantity = '$groqtys' ";
            mysql_query($sql,$CN);
            $response = asort_form_ok("Your order successfully submitted. We will deliver you soon.");
        }
    }
?>

 
     
    