簡體   English   中英

Codeigniter get_where在活動記錄上

[英]Codeigniter get_where on active record

我無法使用codeigniter get_where函數創建查詢以獲取特定數據。 我閱讀並理解了手冊並在我的代碼中使用它,但現在當我要從數據庫查詢時,如下面的代碼,它不起作用。

模型:

public function load_parents () {
  $query = $this->db->get_where('checklist_items', array(('checklist_id' => $checklist_id) && ('parent_id' => $parent_id)));
  $result = $query->result_array ();
  return $result;
}

錯誤: 消息:語法錯誤,意外'=>'(T_DOUBLE_ARROW),期待')'

我知道代碼不對,但還有另一種方法可以讓它運行嗎?

采用

 $query = $this->db->get_where('checklist_items', array('checklist_id' => $checklist_id, 'parent_id' => $parent_id));

用這個 :

<?php 
public function load_parents () 
{
  $query = $this->db->get_where('checklist_items', array('checklist_id' => $checklist_id, 'parent_id' => $parent_id));
  $result = $query->result_array ();
  return $result;
}
?>

嘗試使用此代碼

public function load_parents () {
 $query = $this->db->get_where('checklist_items', array('checklist_id' => $checklist_id , 'parent_id' => $parent_id));
$result = $query->result_array ();
return $result;
}

你不能在數組中使用&&

它會自動考慮and

另一種方式是使用喜歡的地方

public function load_parents () {
 $query = $this->db
                   ->where('checklist_id' => $checklist_id)
                   ->where('parent_id' => $parent_id)
                   ->get('checklist_items');
$result = $query->result_array();
return $result;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM