😕 I am new in php and really confused how to combine two csv into one table.
My Goal is to read test1.csv and place one of the data into an array. From this array I would like to read test2.csv file. Finally I would like to conbine both selected data into one table.
If you could help me, I would really appreciate.
Example:
$fh = fopen("./data/test1.csv", "r");
while (list($dat1, $dat2, $dat3, $dat4, $dat5,$dat6) = fgetcsv($fh, 1024, ","))
{
echo <<<END
<table>
<tr>
<td>$dat1</td>
<td>$dat2</td>
<td>$dat3</td>
<td>$dat4</td>
<td>$dat5</td>
</tr></table>
END;
}
second data file
<?php
Class testing
{
function get_csv_data($webdata)
{
$url = sprintf("http://....=.csv", $webdata);
$fp = fopen($url, 'r');
if (!fp) {
echo 'Error : cannot recieve data.';
} else {
$data = @fgetcsv($fp, 4096, ', ');
fclose($fp);
$this->dataA = $data[0]; // same field as $dat1 and webdata
$this->dataB = $data[1];
$this->dataC = $data[2];
$this->dataD = $data[3]; // same field as $dat5
}
}
}
finally now what I would like to do is to use function "get_csv_data($webdata)" to extract data from the web address for only items for $dat1 and place them into one table like
<table>
<tr>
<td>$dat1</td>
<td>$dat2</td>
<td>$datB</td>
<td>$dat4</td>
<td>$datD</td>
</tr></table>
I hope this explanation was clear. Thanks a lot.