Use start-index and orderby=position:
http://code.google.com/apis/spreadsheets/data/3.0/reference.html#ListParameters

-Vic



On Tue, Feb 22, 2011 at 1:44 PM, Alexandre Plennevaux <[email protected]
> wrote:

> Hi,
>
> I built a php script that accesses my spreadsheet, gets all the rows as a
> list feed, then display one random row out of it. Works fine, but i'd like
> to optimize it.
> Right now, i'm downloading the full data and then randomly chosing one
> element out of the php array.
>
> Is there a way to build a query that makes the random selection happen
> inside the API?
>
> Here is my current code in case it helps.
>
>
> // Zend library include path
> set_include_path(get_include_path() . PATH_SEPARATOR .
> $_SERVER[DOCUMENT_ROOT]."/ZendGdata/library");
>
>
> // credits: http://farinspace.com/saving-form-data-to-google-spreadsheets/
> include_once("Google_Spreadsheet.php");
>
> $u = "gmaillogin";
> $p = "gmailpassword";
>
> $ss = new Google_Spreadsheet($u,$p);
> $ss->useSpreadsheet("My Spreadsheet");
> $ss->useWorksheet('My worksheet');
>
> $rows = $ss->getRows();
> if ($rows){
>     $data  = returnRandomElement($rows);
>     echo '<pre>';
>     print_r($data);
> }
> else {
>    die("error");
> }
>
> // HELPERS
>
> function returnRandomElement($array){
>     return $array[array_rand($array,1)];
> }
>
>

Reply via email to