Skip to content

Instantly share code, notes, and snippets.

@pchatterjee
Last active March 7, 2023 02:23
Show Gist options
  • Select an option

  • Save pchatterjee/858a746705053f86fe1c5a770aedd03e to your computer and use it in GitHub Desktop.

Select an option

Save pchatterjee/858a746705053f86fe1c5a770aedd03e to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Survey (CSV to HTML) example</title>
<meta name="description" content="it workshop 4 - answer">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/2.0.3/pure-min.css">
<style>
body {
margin-left:12px;
margin-top:12px;
font-size:17px;
font-family: "Candara";
}
h4 {
font-size: 20px;
font-weight: 600;
color: #0033cc;
margin-bottom: 8px;
}
td {
vertical-align: top;
padding: 3px;
}
th {
text-align: left;
background: black;
color: white;
padding: 3px;
}
a {
color: #804000;
}
</style>
</head>
<body>
<h4>Survey result from CSV data:</h4>
<table class="pure-table pure-table-horizontal pure-table-striped" style="width:580px;">
<?php
$fh = fopen("survey.csv", "r");
$header = TRUE;
while (!feof($fh)) {
$rec = fgetcsv($fh);
echo '<tr>';
if ($header) {
foreach($rec as $f) {
echo '<th>'.$f.'</th>';
$header = FALSE;
}
}
else {
echo '<td>'.$rec[0].'</td>';
echo '<td>'.$rec[1].'</td>';
echo '<td>'.$rec[2].'</td>';
echo '<td><img width="90px" src="./images/'.$rec[3].'"/></td>';
echo '<td><a href="mailto:'.$rec[4].'">'.$rec[4].'</a></td>';
echo '<td><a href="'.$rec[5].'">'.$rec[5].'</a></td>';
}
echo '</tr>';
}
?>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment