claudios
claudios

Reputation: 6666

Codeigniter get_where on active record

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

Answers (3)

Jatin Raikwar
Jatin Raikwar

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

Manjeet Barnala
Manjeet Barnala

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

Arjun J Gowda
Arjun J Gowda

Reputation: 730

Use

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

Upvotes: 1

Related Questions