Reputation: 6666
I have trouble creating a query to get a specific data using codeigniter get_where function. I read and understand the manual and used it on my code but now when I was about to query from database like the code below it doesn't work.
Model:
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;
}
The Error: Message: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')'
I know the code is not right but is there another way to make it run?
Upvotes: 1
Views: 1795
Reputation: 394
Try using this code
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;
}
You can not use &&
in array.
It will automatically consider and
.
Another way is using where like
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;
}
Upvotes: 1
Reputation: 2995
use this :
<?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;
}
?>
Upvotes: 1
Reputation: 730
Use
$query = $this->db->get_where('checklist_items', array('checklist_id' => $checklist_id, 'parent_id' => $parent_id));
Upvotes: 1