Here's the array to store the value from the DB:
$dataTitle[0] = "TIR";
$dataTitle[1] = "OIL";
$dataTitle[2] = "SPK";
$dataDesc[0] = "Tires";
$dataDesc[1] = "Oil";
$dataDesc[2] = "Spark Plugs";
$dataValue[0] = "100";
$dataValue[1] = "10";
$dataValue[2] = "4";
I can use the following to insert the data into 2D array manually but it doesn't serve purpose if i have 100 or more row records to be inserted. That's why FOR loop is needed for the below.
$ResultView = array(array($dataTitle[0], $dataDesc[0], $dataValue[0]),
array($dataTitle[1], $dataDesc[1], $dataValue[1]),
array($dataTitle[2], $dataDesc[2], $dataValue[2])
);
If am using the following FOR LOOP, the 2D array only stored the last row record and omitted the 1st and 2nd row records.
for ($i=0; $i<=2; $i++) {
$ResultView = array(array($dataTitle[$i], $dataDesc[$i], $dataValue[$i])
);
}
When I issue the output script below for the for loop above, I get the output value for the 3rd ROW and missing 1st and 2nd Row result. Please help!
for ($row=0; $row<=2; $row++) {
for ($col=0; $col<=2; $col++) {
echo $ResultView[$row][$col]."  | ";
}
echo '<br />';
}
But, I am looking a way the use FOR Loop instead for the above. How?
The actual outputs are:
Row 1 => TIR | Tires | 100
Row 2 => OIL | Oil | 10
Row 3 => SPK | Spark Plugs | 4
Please advice.