I have a question to ask. Firstly, I have a table, where the parent has parent_id is 0 and the child has parent_id equal parent id. parent_id of all children are stored as a json encoded array (one child record can have many parents).
So, how can I get all the children of the parent when I pass one parent id. I tried but it won't work and I don't have a clue.
Here's the code:
function get_child_product($parent_id, $limit, $start) {
$this -> db -> from('product');
$this -> db -> where(json_decode('parent_id'), $parent_id);
$this -> db -> limit($limit, $start);
$this -> db -> order_by('order', 'asc');
$this -> db -> order_by('id', 'desc');
$query = $this -> db -> get();
return $query -> result();
}
Problem solved:
function get_child_product($parent_id, $limit, $start) {
$this -> db -> from('product');
$this -> db -> like('parent_id', '"' . $parent_id . '"');
$this -> db -> limit($limit, $start);
$this -> db -> order_by('order', 'asc');
$this -> db -> order_by('id', 'desc');
$query = $this -> db -> get();
return $query -> result();
}