0

當我嘗試從Google BigQuery中的表中提取的內容讀取數組中的行時,它只將第一行讀入數組。Google BigQuery將行讀取到數組中

我已經做到了在其他代碼相同的方式,不知道這是爲什麼不讀所有的行

<?php 
    function top10($chart){ 
     $client = new Google_Client(); 
     $client->useApplicationDefaultCredentials(); 
     $client->addScope(Google_Service_Bigquery::BIGQUERY); 
     $bigquery = new Google_Service_Bigquery($client); 
     $projectId = 'projectID'; 

     $request = new Google_Service_Bigquery_QueryRequest(); 

     $query = "SELECT First_Name, Last_Name, G FROM [" . $chart. "] ORDER BY G DESC LIMIT 10"; 

     $request->setQuery($query); 

     $response = $bigquery->jobs->query($projectId, $request); 
     $rows = $response->getRows(); 

     $ii = 0; 
     $i = 0; 
     foreach ($rows as $row) 
     { 
      foreach ($row['f'] as $field) 
      { 
       $Info[$i][$ii] = $field['v']; 
       $ii++; 
      } 
      $i++; 
     } 
    } 
?> 

回答

1

你需要使用這樣的事情:

$rows = $queryResults->rows(); 
     foreach ($rows as $row) { 
      printf('--- Row %s ---' . PHP_EOL, ++$i); 
      foreach ($row as $column => $value) { 
       printf('%s: %s' . PHP_EOL, $column, $value); 
      } 
     } 

完整示例here

相關問題