using Google Docs as a database? using Google Docs as a database? xml xml

using Google Docs as a database?


So, while it might not be wise or scalable, yes, you can do it. Try this code:

<?php$url = "https://spreadsheets.google.com/pub?hl=en&hl=en&key=0AupgXsRU8E9UdC1DY0toUUJLV0M0THM4cGJTSkNSUnc&output=csv";$row=0;if (($handle = fopen($url, "r")) !== FALSE) {    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {        $num = count($data);        echo "<p> $num fields in line $row: <br /></p>\n";        $row++;        for ($c=0; $c < $num; $c++) {            echo $data[$c] . "<br />\n";        }    }    fclose($handle);}

Basically, publish the spreadsheet as public, change output to csv (from the default HTML) by manually editing the URL (ie, output=csv), fetch it, and then iterate over it line by line using fgetcsv.

If the spreadsheet looks like this:

enter image description here

This will output the following for the csv in question:

array(2) {  [0]=>  string(4) "Name"  [1]=>  string(5) "Value"}array(2) {  [0]=>  string(3) "Foo"  [1]=>  string(5) "13123"}array(2) {  [0]=>  string(3) "Bar"  [1]=>  string(3) "331"}


You could try this just for fun. But if you just need a communal calendar, use something like Google Calendar. The Google Calendar API enables you to update your calendar from a program. And you can embed a calendar in your website using the Google Embeddable Calendar Helper.

Not as much fun as programming it from scratch though ... ;-)


I wrote some PHP with Zend framework to read Google spreadsheets.Code available here http://www.geekzone.co.nz/hellonearthisman/6647