2015-06-27 44 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