2015-06-27 80 views
1

quickbooks API只爲任何SQL查詢返回1000個項目,所以我需要批量查詢。我的問題是,我如何將結果一起添加到php中?如何組合來自批量查詢的結果集?

$customers = []; 
$start_position = 1; 
for ($i = 1; $i <= $number_of_queries; $i++) { 
    $customers[$i] = $customer_service->query(
     $this->qb->context, 
     $this->qb->realm, 
     "SELECT * FROM Customer STARTPOSITION " . $start_position . " MAXRESULTS 1000" 
    ); 
    $start_position += 1000; 
} 

return json_encode($customers); 

問:我怎樣才能結合$customers[1]$customers[2]$customers[3]等爲包含所有客戶數據的一個數組?

或者,如果最好做這個客戶端,這怎麼可以在JavaScript中完成?

我已經看過array_mergearray operators但這些解決方案覆蓋,如果鍵是相同的,他們是。

此外,我已經在JavaScript中調查了concat。但是,我無法得到這個工作。

有沒有人有任何組合批處理查詢結果集的經驗?

Screen Shot of Console

+0

鍵的外觀如何? – Cymen

+0

查詢的結果是一組客戶。每個客戶擴展到包含所有客戶數據(幾個不同的鍵)的鍵「* _data」的對象。 –

+0

它是構成客戶的匿名對象的數組嗎?像JSON中的[{...},{...},{...}]'?還是更像'{customer_1:{..},customer_2:{...}}'。簡而言之,也許會粘貼一個將在'$ customers' arary中的值之一的示例。我想我們需要更多關於結構的細節來建議如何合併結果集。 – Cymen

回答

3

您可以嘗試使用PHP的array_merge()功能。

$customers = []; 
$start_position = 1; 
for ($i = 1; $i <= $number_of_queries; $i++) { 
    $results = $customer_service->query(
     $this->qb->context, 
     $this->qb->realm, 
     "SELECT * FROM Customer STARTPOSITION " . $start_position . " MAXRESULTS 1000" 
    ); 
    $start_position += 1000; 
    $customers = array_merge($customers, results); 
} 

return json_encode($customers); 
+0

好吧,我會被詛咒的。 –

+0

很高興爲您服務! – JME