Sorry but I dont know how to explain my problem but rather I will demonstrate my problem here.
This is what I get when I used print_r()
Array ( [0] => 2 [1] => 200 )
Array ( [0] => 5000 [1] => 1000 )
Array ( [0] => 2 [1] => 200 )
Array ( [0] => 5000 [1] => 1000 )
Array ( [0] => 2 [1] => 200 )
Array ( [0] => 5000 [1] => 1000 )
Array ( [0] => 2 [1] => 200 )
Array ( [0] => 5000 [1] => 1000 )
Array ( [0] => 4 [1] => 300 )
Array ( [0] => 10000 [1] => 1500 )
Array ( [0] => 4 [1] => 300 )
Array ( [0] => 10000 [1] => 1500 )
Array ( [0] => 4 [1] => 300 )
Array ( [0] => 10000 [1] => 1500 )
Array ( [0] => 4 [1] => 300 )
Array ( [0] => 10000 [1] => 1500 )
Array ( [0] => 3 [1] => 100 )
Array ( [0] => 7500 [1] => 500 )
Array ( [0] => 3 [1] => 100 )
Array ( [0] => 7500 [1] => 500 )
Array ( [0] => 3 [1] => 100 )
Array ( [0] => 7500 [1] => 500 )
Array ( [0] => 3 [1] => 100 )
Array ( [0] => 7500 [1] => 500 )
And this is my code
foreach ($supp_dtl_1 as $key => $value) {
$arr = explode(',',$value->unit_price);
$arr1 = explode(',',$value->total_amount);
foreach($arr as $cell){
foreach($arr1 as $cell1){
//echo print_r($arr);
//echo print_r($arr1);
<td><input type="text" value="<?php echo $cell; ?>"></td>
<td><input type="text" value="<?php echo $cell1; ?>"></td>
}
}
}
This is the result of the above code
2 | 5000 | 2 | 1000 | 200 | 5000 | 200 | 1000 | 4 | 10000 | 4 | 1500 | 300 | 10000 | 300 | 3 | 7500 | 3 | 500 | 100 | 7500 | 100 | 500
2 | 5000 | 2 | 1000 | 200 | 5000 | 200 | 1000 | 4 | 10000 | 4 | 1500 | 300 | 10000 | 300 | 3 | 7500 | 3 | 500 | 100 | 7500 | 100 | 500
The Expected output should be something like this
2 | 5000 | 3 | 7500 | 4 | 10000
200 | 1000 | 100 | 500 | 300 | 1500
This is my data in db and the result of my query.
Name | unit_price | total_amount
j1 | 2 | 5000
j1 | 200 | 1000
j2 | 3 | 7500
j2 | 100 | 500
j3 | 4 | 10000
j3 | 300 | 1500
I don't really know what exactly you want, but I hope the following code will help. You don't need to nest your second array with another for loop, instead, you can iterate it under the same loop as the first array with $key.
foreach($arr as $key => $cell){
//echo print_r($arr);
//echo print_r($arr1[$key]);
<td><input type="text" value="<?php echo $cell; ?>"></td>
<td><input type="text" value="<?php echo $arr1[$key]; ?>"></td>
}
Try this
<?php
foreach ($supp_dtl_1 as $key => $value) {
$arr = explode(',',$value->unit_price);
$arr1 = explode(',',$value->total_amount);
foreach($arr as $key2 => $cell){
echo '<td><input type="text" value="'.$cell.'"></td>';
echo '<td><input type="text" value="'.$arr1[$key2].'"></td>';
}
}