-
-
Save Alexander-Pop/a378a3a33d7e430c2a10ffd7bb8c64af to your computer and use it in GitHub Desktop.
Display CSV file as HTML Table with first 2 columns clickable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = "releases.csv"; // your csv file name | |
$directory = $_SERVER['DOCUMENT_ROOT']."/var/releases/".$file; // path to file | |
$row = 1; // horizontal | |
if (($handle = fopen($directory, "r")) !== FALSE) { | |
echo '<table id="releases-calendar">'; | |
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { // change ";" if your csv delimiter is different... | |
// var_dump($data); | |
$num = count($data); | |
if ($row == 1) { | |
echo '<thead class="thead"><tr>'; | |
} else { | |
echo '<tr>'; | |
} | |
for ($c=0; $c < $num; $c++) { | |
if(empty($data[$c])) { | |
$value = " "; | |
} else{ | |
$value = $data[$c]; | |
} | |
// Getting URLs from Array | |
$stackUrl = $data[4]; // data Stream | |
$urlStack = explode('*****', $stackUrl); // Explode | |
$urlOne = $urlStack[0]; // Get URL 1 | |
$urlTwo = $urlStack[1]; // Get URL 2 | |
if ($row == 1) { | |
echo '<th>'.$value.'</th>'; | |
} else { | |
/* remove if you don't the first 2 columns to be clickable */ | |
if ($data[$c] == $data[0]) { | |
echo '<td><a href="'.$urlOne.'">'.$value.'</a></td>'; | |
} else if ($data[$c] == $data[1]) { | |
echo '<td><a href="'.$urlTwo.'">'.$value.'</a></td>'; | |
} else { | |
/* end part to be removed. */ | |
echo '<td>'.$value.'</td>'; | |
} | |
} | |
} | |
if ($row == 1) { | |
echo '</tr></thead><tbody class="tbody">'; | |
} else { | |
echo '</tr>'; | |
} | |
$row++; | |
} | |
echo '</tbody></table>'; | |
fclose($handle); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment