Created
January 26, 2014 14:53
-
-
Save blackspike/8633926 to your computer and use it in GitHub Desktop.
Google spreadsheets as a CMS
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
<html> | |
<head> | |
<title>Welcome!</title> | |
<style> | |
body {font-family: arial; background: lightgrey} | |
table {margin: 30px auto; background: white; border-collapse: collapse} | |
tr:nth-child(odd) {background-color: #eee;} | |
th {text-align: left; padding: 20px 20px; cursor: pointer} | |
th:hover {background: white} | |
td {padding: 5px 20px; border: 1px solid lightgrey} | |
</style> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> | |
<script type="text/javascript" src="http://tablesorter.com/jquery.tablesorter.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
//make it sortable | |
$(".csvTable").tablesorter(); | |
}); | |
</script> | |
</head> | |
<body> | |
<?php | |
# set your csv spreadsheet url here | |
$csv = "http://spreadsheets.google.com/pub?key=t6wIcgSnjd6eJX1NbaOqWtg&output=csv"; | |
# if there is a spreadsheet... | |
if($csv !== '') { | |
# write an html table | |
echo "<table class='csvTable'>"; | |
# open the csv | |
$handle = fopen($csv, "r"); | |
$data = fgetcsv($handle, 1000, ","); | |
echo "<thead><tr>"; | |
# column headers from 1st row of csv: | |
foreach($data as $value) { | |
echo "<th>$value</th>"; | |
} | |
echo "</tr></thead>\n<tbody>\n"; | |
# data rows: | |
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { | |
echo "<tr>"; | |
foreach($data as $value) { | |
# write table cell data | |
echo "<td>$value</td>"; | |
} | |
echo "</tr>\n"; | |
} | |
echo "</tbody>\n</table>\n"; | |
} | |
else { echo "Can't connect to google, sorry!"; } | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment