Overview
I have created a script that attempts to parse an uploaded CSV file, loop through the rows and columns, and out putting them into a semantic HTML table. I have tried to add a condition . if statement that would only display the table rows that have a value in col 6 grater than 0.40 (i am filtering imported CSV's to remove table rows that have bounce rates lower than 40% n the column)
Excuse
I can't see the wood through the trees, so to speak here. I am a junior developer, struggling to actually comprehend debugging in PHP compared to .NET and Visual Studio. PHP is much harder to debug IMO. Anyway no debates I'm a newbie maybe I'm missing things, regardless I'd appreciate some help. And I apologize for any oversights or anything silly, I just need a bit of help pointing out where I went wrong and how I could improve?
It's a fairly simple script I'm sure :(
<?php
//error Reporting
ini_set('display_errors', 1);
error_reporting(E_ERROR);
//parse imported CSV
$csvData = file_get_contents($_FILES['minefile']['tmp_name'], 'r+');
$lines = explode("\n", $csvData);
$array = array();
foreach ($lines as $line) {
$array[] = str_getcsv($line);
} //$lines as $line
//count rows & cols
$colCount = count($array[0]);
$rowCount = count($array);
$showRow = true;
//start table html
echo '<table width="100%">';
//Start looping through csv row (line) by row (line)
for ($row = 0; $row <= $rowCount; $row++) {
// debug var row loop - echo "<h1>".$col."</h1>";
// echo '<h1>'.$hideRow ? 'true' : 'false'.'</h1>';
//if index is 0 it must be the header (in this case)
if ($row == 0) {
//output table head tag
echo '<thead>';
}
else {
//check bounce rate column (6) for a bounce rate higher than 40%
if ($showRow == true) {
//show row
echo '<tr>';
}
//
else {
//hide row
echo '<tr style="display:none;">';
}
}
for ($col = 0; $col <= $colCount; $col++) {
if ($row == 0) {
//
echo '<th>' . $array[$row][$col] . '</th>';
} //$row == 0
else {
if ($array[$row][$col] >= 0.40 && $col == 5)
{
$showRow = true;
}
echo '<td>' . $array[$row][$col] . '</td>';
}
} //$col = 0; $col <= $colCount; $col++
if ($row == 0) {
echo '</thead>';
} //$row == 0
else {
echo '</tr>';
}
} //$row = 0; $row <= $rowCount; $row++
echo "</table>";
echo "<h1>Debugging</h1>";
echo "<h3>Col Count: " . $colCount . " </h3>";
echo '<h3>Row Count: ' . $rowCount . '</h3>';
?>