我无法使delete_record函数工作。下面是我目前使用的delete_record代码:
$qb->db_id = $myQbTables["table1"]; //using table 1 now
$queries = array( //this is the where clause now for the delete query
array(
'fid' => '12',
'ev' => 'EX',
'cri' => '1175'
),
array(
'fid' => '8',
'ev' => 'EX',
'cri' => $Child_ID
)
);
$results = $qb->do_query($queries, '', '', 'a', '1', 'structured', 'sortorder-A'); //get all results
if($results->errCode !== 0) {
echo $results->errTxt;
}
print_r($results);
foreach($results->table->records->record as $record){ //getting results of delete query
$Deletevar = $record->f[11];
$deleted = $qb->delete_record($Deletevar); //deleting results
print_r($deleted);
}我知道'cri‘与我的quickbase中的内容相匹配,但我似乎不能使用f3删除它!
注意事项
我发现了我遇到的主要问题!如果您使用QB进行API调用,则删除记录和清除记录不包括应用令牌!!请使用以下代码更新delete_records函数!
public function delete_record($rid) {
if($this->xml) {
$xml_packet = new SimpleXMLElement('<qdbapi></qdbapi>');
$xml_packet->addChild('rid',$rid);
$xml_packet->addChild('ticket',$this->ticket);
$xml_packet->addChild('apptoken',$this->app_token);
$xml_packet = $xml_packet->asXML();
$response = $this->transmit($xml_packet, 'API_DeleteRecord');
}
else {
$url_string = $this->qb_ssl . $this->db_id. "?act=API_DeleteRecord&ticket=". $this->ticket
."&apptoken=".$this->app_token."&rid=".$rid;
$response = $this->transmit($url_string);
}
return $response;
}发布于 2015-09-15 00:23:06
我想你可能在查询中遗漏了什么。如果您试图获取字段12为1157,字段8等于$Child_ID的记录列表,则需要将AND添加到查询中。当在URL中使用API时,如果子ID为77,查询将是&query={12.EX.1175}AND{8.EX.77}。要在中这样做,您可以在第一个查询数组后面的所有数组中添加'ao' => 'AND'。尝试更新$queries数组如下:
$queries = array( //this is the where clause now for the delete query
array(
'fid' => '12',
'ev' => 'EX',
'cri' => '1175'
),
array(
'ao' => 'AND', // Saying that 12.EX.1175 AND 8.EX.$Child_ID
'fid' => '8',
'ev' => 'EX',
'cri' => $Child_ID
)
);我的PHP技能不是特别好,但您需要做更多的工作才能获得ID#记录。在最初的代码中,我认为$record->f[3]将返回到SimpleXMLObject,用于数组中的第三个字段。这不一定是字段ID 3(记录ID)。您可以选择不使用结构化格式(并将所有代码更改为匹配),也可以添加一个循环,当它使用id 3到达字段时,它会遍历所有字段并删除:
foreach($results->table->records->record as $record){ //getting results of delete query
//Loop through all fields to find id 3
foreach($record->f as $field){
if($field['id'] == "3"){
$Deletevar = $field['id'];
$deleted = $qb->delete_record($Deletevar); //deleting result
print_r($deleted);
break; //Stops this loop since FID 3 was found
}
}
}一些性能注意事项:如果您没有使用任何其他字段,则可以通过传递一个仅为“3”的clist,将查询设置为只返回记录If。而且,每个delete_record()都是一个单独的API调用。还有一种方法purge_records允许您传递一个查询,并且Quickbase删除与您的查询匹配的所有记录。您可能需要考虑使用purge_records(),因为您可以使用它来代替您的do_query()并避免所有的循环。它使用较少的资源和Quickbase进行处理。
https://stackoverflow.com/questions/32571070
复制相似问题