I have a large form where 3 arrays are sent to the controller from the form: product_code | quantity | cost.
$id = $request->get('product_code'); // GRAB PRODUCT DATA FROM POST ARRAY
$qty = $request->get('quantity'); // GRAB QUANTITY DATA FROM POST ARRAY
$cost = $request->get('cost'); // GRAB COST DATA FROM POST
The output from the request on all three arrays is here: PasteBin
My problem is I can not figure out how best to loop through each of these three arrays so that I can insert into MySQL the values in the correct order. I have tried both a foreach, a nested foreach and a for loop and I have not managed yet to get all three values inserting onto a single row.
I don't think the HTML is very relevant, but here is a sample anyway:
<div class="well form-group ">
<div class="col-sm-2 col-md-2">
<label for="nails_staples">Nails & Staples:</label>
</div>
<div class="col-sm-4 col-md-4">
<select class="form-control product_id" name="product_code[10]">
<option selected="selected" value="">None</option>
<option value="8769">1 1/4 Coil Nails - box | $26.00</option>
<option value="6678">2" Hot Dipped Shake Nails | $135.00</option>
</select>
</div>
<div class="col-sm-1 col-md-1">
<label for="nails_req">Quantity:</label>
</div>
<div class="col-sm-2 col-md-2">
<input class="form-control quantity" name="quantity[10]" type="text">
</div>
<div class="col-sm-1 col-md-1">
<label for="cost">Cost:</label>
</div>
<div class="col-sm-2 col-md-2">
<input class="form-control cost" readonly="readonly" name="cost[]" type="text">
</div>
</div>
product_code
array looks like a<select>
tag, which is handled strangely in different browsers for multiple selections, and the sort order can change. Can you give an example of input data for the 3 arrays, or the whole form? Maybedd($request);
in your controller and post it to pastebin? – QuickDanger Mar 2 '16 at 0:10