showing array by group on php is not working as expected -
i want straight forward.
it html form have created touch of javascript. has option increase/delete table (i didn't attached code here- wanted make sure know in case. ). here in example using 3 rows.
<tbody> <tr> <td><input class="case" type="checkbox"/></td> <td><input type="text" data-type="productcode" name="itemno[]" id="itemno_1" class="form-control autocomplete_txt" autocomplete="off" placeholder="enter imei number"></td> <td><input type="text" data-type="productname" name="itemname[]" id="itemname_1" class="form-control autocomplete_txt" autocomplete="off" placeholder="brand"></td> <td><input type="text" data-type="productname" name="brand[]" id="itemname_2" class="form-control autocomplete_txt" autocomplete="off" placeholder="model"></td> <td><input type="number" name="price[]" id="price_1" class="form-control changesno" autocomplete="off" onkeypress="return isnumeric(event);" ondrop="return false;" onpaste="return false;"></td> <td><input type="number" value="1" name="quantity[]" id="quantity_1" class="form-control changesno" autocomplete="off" onkeypress="return isnumeric(event);" ondrop="return false;" onpaste="return false;" disabled></td> <td><input type="number" name="total[]" id="total_1" class="form-control totallineprice" autocomplete="off" onkeypress="return isnumeric(event);" ondrop="return false;" onpaste="return false;" disabled></td> </tr> </tbody>
once process through php post method, data pass. called them in specific loop following.
$itemno = $_post['itemno']; $itemname = $_post['itemname']; $brand = $_post['brand']; $price = $_post['price']; foreach($itemno $itemno) { echo $itemno.'<br/>'; } foreach( $itemname $itemname ) { print $itemname.'<br/>'; } foreach( $brand $brand ) { print $brand.'<br/>'; } foreach( $price $price ) { print $price.'<br/>'; }
its gives me output following:
field 1 data of 1st row field 1 data of 2nd row field 1 data of 3rd row field 2 data of 1st row field 2 data of 2nd row field 2 data of 3rd row field 3 data of 1st row field 3 data of 2nd row field 3 data of 3rd row field 4 data of 1st row field 4 data of 2nd row field 4 data of 3rd row
i struggling output this--
field 1 data of 1st row field 2 data of 1st row field 3 data of 1st row field 4 data of 1st row field 1 data of 2nd row field 2 data of 2nd row field 3 data of 2nd row field 4 data of 2nd row field 1 data of 3rd row field 2 data of 3rd row field 3 data of 3rd row field 4 data of 3rd row
so can use single loop required output.
any idea or should appreciated.
thanks fiona
you can utilize $key
part of foreach($array $key => $value)
desired results. see http://php.net/manual/en/control-structures.foreach.php
$itemnos = $_post['itemno']; $itemnames = $_post['itemname']; $brands = $_post['brand']; $prices = $_post['price']; foreach($itemnos $key => $value) { echo '<p>'; echo $itemnos[$key].'<br/>'; echo $itemnames[$key].'<br/>'; echo $brands[$key].'<br/>'; echo $prices[$key]; echo '</p>'; }
Comments
Post a Comment