I have the following code that reads a .csv file that than outputs the result in the form of a HTML table:
$fhdrop = fopen("ac.csv", "r");
while (!feof($fhdrop) ) {
$at[] = fgetcsv($fhdrop, 1024);
}
$fhdrop2 = fopen("rc.csv", "r");
while (!feof($fhdrop2) ) {
$at2[] = fgetcsv($fhdrop2, 1024);
}
?>
<table border=1>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
<tr>
<td><?php echo $at[0][0] ?></td>
<td><?php echo $at[0][1] ?></td>
<td><?php echo number_format($at[0][1]*$at2[0][1],2) ?></td>
<td><?php echo number_format($at[0][1]*$at2[1][1],2) ?></td>
</tr>
<tr>
<td><?php echo $at[1][0] ?></td>
<td><?php echo $at[1][1] ?></td>
<td><?php echo number_format($at[1][1]*$at2[0][1],2) ?></td>
<td><?php echo number_format($at[1][1]*$at2[1][1],2) ?></td>
</tr>
<tr>
<td><?php echo $at[2][0] ?></td>
<td><?php echo $at[2][1] ?></td>
<td><?php echo number_format($at[2][1]*$at2[0][1],2) ?></td>
<td><?php echo number_format($at[2][1]*$at2[1][1],2) ?></td>
</tr>
<tr>
<td><?php echo $at[3][0] ?></td>
<td><?php echo $at[3][1] ?></td>
<td><?php echo number_format($at[3][1]*$at2[0][1],2) ?></td>
<td><?php echo number_format($at[3][1]*$at2[1][1],2) ?></td>
</tr>
</table>
The contents of ac.csv are:
a, 5,
b, 10,
c, 24,
d, 21
The contents of rc.csv are:
not, 1.87,
notatall, 1.78
As you can guess from the original code, I need to do multiplication in the second column. In the second row and third column, for instance, I need 5*1.87 and 5*1.78. So basically a
* not
and a
* notatall
.
My code is not very efficient. How can I make it more efficient?