不能使用QueryResult类型的对象作为数组,使用带有CI的Salesforce库

时间:2016-09-15 09:43:24

标签: php arrays codeigniter salesforce

我收到了错误

  

"不能使用QueryResult类型的对象作为数组"

我只是想从记录数组中获取状态名称但是,我只能设法得到这个错误"不能使用QueryResult类型的对象作为数组"

Model.php

In [178]:
df[3] = df[3].astype(int)
df

Out[178]:
     0       1      2    3    4    5
0  XYZ   BALSO  PISCO  100  660  Cop
1  XYZ   TONTO  LOLLO  195  500  nan
2  XYZ   CALLO  WANDA  400  500  nan
3  XYZ  AZUNGO  FINGI  500  500  nan

Controller.php这样

public function getstatename()
{   
$statename = $this->salesforce->query ("SELECT State__c FROM  RI_School_List__c group by State__c");

return $statename;  
}

3 个答案:

答案 0 :(得分:1)

这是已解决的代码感谢@Anant

<强> Model.php

public function getstatename()
{   
  $statename = $this->salesforce->query ("SELECT State__c FROM  RI_School_List__c group by State__c");
  $state_array = array();

  foreach ($statename as $row){ 
    $state_array[] = $row->State__c; 
  }   
  return $state_array; 
}

<强> Controller.php这样

public function index() {
$data['getstatename'] = $this->Footer_model->getstatename();            
            $this->load->view('footer', $data);
}

答案 1 :(得分:1)

实际上$statenameresult-set对象而不是数组。

所以你需要这样做: -

<强> Model.php: -

public function getstatename(){ 
    $statename = $this->salesforce->query ("SELECT State__c FROM RI_School_List__c group by State__c"); 
    $state_array = array(); // create an array
    foreach ($statename as $row){ 
        $state_array[] = $row->State__c;  // assign value to array
    } 
    return $state_array; // return array
} 

<强> Controller.php这样: -

public function index() { 
    $data['getstatename'] = $this->Footer_model->getstatename();
    echo "<pre/>";print_r($data['getstatename']); // check this and accordingly change you code further 
    $this->load->view('footer', $data);
}

答案 2 :(得分:0)

看看你能否做到

$data['getstatename']->fetchRow();