Following is the sample of my CSV file:
Name | USD ------------ Ifone | 500 Ufone | 600
I want to read my csv file where my php script reads the first row and then (How to) create table accordingly as per the elements of the first row being returned like from the above example the row elements will be Name and USD
.
Create table csv
{
$column1 varchar (50)
$column2 varchar (50)
}
Then (How to) store the elements starting from the 2nd row and so on in the created table. Kindly let me know what is an appropriate way to do that.
Thanks,
Following function I used to get data from my csv file:
$row = 1;
if (($handle = fopen("mycsv.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}