My experience with php is limited, but I’m working on a tiny project that I feel so close to achieving, but I just can’t get it to work properly.
I have this results.csv that has let’s say these lines:
Balle Klorin,12,1345,ACME,[email protected]
And I have this results.php that includes this:
$inputfile = file(“results.csv”);
$data_lines = array();
foreach ($inputfile as $line)
$data_lines = explode("\r\n", $line);
//Get column headers.
$first_line = array();
foreach ($data_lines as $dl)
$first_line = explode(",", $dl);
$headers = array();
foreach ($first_line as $fl)
$headers = $fl;
// Get row content.
$data_cells = array();
for ($i = 1; $i < count($data_lines); $i++)
$data_cell = array();
for ($j = 0; $j < count($headers); $j++)
$data_cell[$j] = substr($data_lines[$i][$j], strpos($data_lines[$i][$j], “,”));
$data_cells[$i] = $data_cell;
?>HTML Table With PHP <?php foreach ($headers as $header): ?> <?php endforeach; ?> <?php foreach ($data_cells as $data_cell): ?> <?php for ($k = 0; $k < count($headers); $k++): ?> <?php endfor; ?> <?php endforeach; ?>
|<?php echo $header; ?>|
|<?php echo $data_cell[$k]; ?>|
Now, what I’m trying to do is show this csv nicely in an html table. For some reason I can’t get the cells into the correct cells, they all end up like in the attached picture.
The entries from the name-column are gone and it’s all in one cell… Can anyone help me here?
I also want this sorted by highest kills first, then by lowest deaths, but that will probably be quite easy once I get this fixed…
I’ve been googling for days and trying all sorts of methods to do this, but this is actually the closest I’ve come to what I want to accomplish. Can some of you please push me in the right direction here?