質問があります。まず、親がparent_id
is0
で、子がparent_id
等しい親 ID を持つテーブルがあります。parent_id
すべての子のうちの 1 つが json エンコードされた配列として格納されます (1 つの子レコードは多くの親を持つことができます)。
では、1 つの親 ID を渡したときに、親のすべての子を取得するにはどうすればよいでしょうか。やってみたけどうまくいかないし、わからない。
コードは次のとおりです。
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();
}
問題が解決しました:
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();
}