php - Codeigniter 2.1 - MySQL JOIN -
i have 2 tables:
menu ->id_menu ->title ->page_id ->order pages ->id_page ->title ->page ->slug
this select function:
public function get_all_menu() { return $this->db ->select('menu.*, pages.id_page, pages.title page_title') ->from($this->table) ->join('pages','id_page = page_id') ->order_by($this->order_by) ->get() ->result_array(); }
here problem - item in menu can connected page, can solo (without connection page). means page_id in menu table can 0. if page_id 0, not getting row above query. how can items in menu (those connected , not connected page )?
as requested comments:
you need use "left join" retrieve partial or incomplete values tables.
in case, regular join looking matches between 2 tables. since there's no id 0 in 1 of tables, match can't retrieved , row won't selected.
using left join (or right join when appropriate, based on 1 "incomplete" table) if match isn't retrieved, outcome contain rows aren't matched, nulls in other table's values
Comments
Post a Comment