Hi (i have attached all files relevant to my question),
I have a slight problem with a project I am creating for school. The project has asked to first of all display values from a .csv file using php which I have done…
The next second task however actually asks to multiply a value from the first csv file with a number from a second csv file.
The CSV files look like the following
The calculation would be 11.97(from metals.csv) * 1.57 (from rates.csv) and thus creating an exchange rate.
=============================================
[size=14pt]metals.csv[/size]
[table]
[tr]
[td]Type of Metal[/td]
[td]Price Per Gram (GBP)[/td]
[/tr]
[tr]
[td]9 Carat Gold[/td]
[td]11.97[/td]
[/tr]
[tr]
[td]Silver[/td]
[td]0.49[/td]
[/tr]
[/table]
=============================================
[size=14pt]rates.csv[/size]
[table]
[tr]
[td]USD[/td]
[td]EUR[/td]
[/tr]
[tr]
[td]1.57[/td]
[td]1.23[/td]
[/tr]
[/table]
=============================================
The results of the calculation would then need to be displayed in the table.
Here is my code so far, which basically just displays information from the metals.csv file but I have no idea how to conduct a calculation between two csv files??? someone please help:
[php]<?php
$cnx = fopen(“metals.csv”, “r”); //open example.csv
echo(“”); // echo the table
while (!feof ($cnx)) { // while not end of file
$buffer = fgets($cnx); // get contents of file (name) as variable
$values = explode(",", $buffer); //explode “,” between the values within the contents
echo “”;
for ( $j = 0; $j < count($values); $j++ ) { //
echo("");
}
echo"";
};
echo("
Type of Metal | Price Per Gram (GBP) | Price Per Gram (USD) | Price Per Gram (EUR) |
---|---|---|---|
$values[$j] |
fclose($cnx); //close filename variable
?>[/php]
calculation.zip (921 Bytes)