I am new to use the csv file. I want to use CSV file so that updating the data of my table will be easier.
The EXPECTED TABLE should be like this: https://www.dropbox.com/s/e6sg9d3fsh8n1v9/table.png?dl=0
I have generated .csv file for above table as below:
Americas Center,XX%,xxxx,xxxxx,Irving,Norcross,San Carlos
Asheville,XX%,xxxx,xxxxx,Louisville,Northfield,San Diego
Austin,XX%,xxxx,xxxxx,Manchester,Overland Park,Telecommuters
Buffalo Grove,XX%,xxxx,xxxxx,Marlborough,Pennsylvania,Tempe
Charlotte,etc,,,Memphis,Plano,Valencia
Columbia,,,,Milpitas,Raleigh,
Coopersville,,,,Morgan Hill,RTS,
I have read .csv file in PHP as below:
<table class="local table-fill">
<?php
$file_handle = fopen("flextronics.csv", "r");
while (!feof($file_handle) ) {
$line_of_text = fgetcsv($file_handle, 1024);
?>
<tr>
<td class="text-left" style="color:#FFF;background:#9ea7af;"><?php print $line_of_text[0]; ?></td>
</tr>
<tr>
<td class="text-left" style="color:#FFF;background:#9ea7af;"><?php print $line_of_text[1]; ?></td>
</tr>
<tr>
<td class="text-left" style="color:#FFF;background:#9ea7af;"><strong>Eligible:</strong> <?php print $line_of_text[2]; ?></td>
</tr>
<tr>
<td class="text-left" style="color:#FFF;background:#9ea7af;"><strong>Registered:</strong> <?php print $line_of_text[3]; ?></td>
</tr>
<tr>
<td class="text-left"><?php print $line_of_text[4]; ?></td>
</tr>
<tr>
<td class="text-left"><?php print $line_of_text[5]; ?></td>
</tr>
<tr>
<td class="text-left"><?php print $line_of_text[6]; ?></td>
</tr>
<?php
}
fclose($file_handle);
?>
</table>
I am getting RESULT like this: https://www.dropbox.com/s/fjqoj1400nqkgnx/result.png?dl=0
RESULT is NOT like the above EXPECTED TABLE. I tried to get table by changing PHP code, but not able to get data at correct place of table. I could not understand what's going wrong either arrangement of .csv file data or reading that file in PHP. There is another problem like in EXPECTED TABLE, rows css are different. So thinking that, I can not use single <tr> and <td> to fetch data. How can I do this?