I have these tables
cat (holds main data for categories) id_cat, original name
cat_lang (holds cat details in different languages) lang, id_cat,local_name
cat_media (holds cat media) id_cat, id_media, usage (may have base or big)
media (holds image information) id_media, name, path
I made a query which returns sub categories of selected category like this.
$this->db->select('*')
->from('cat')
->join('cat_lang','cat.id_cat = cat_lang.id_cat','left outer')
->join('cat_media','cat.id_cat= cat_media.id_cat','left outer')
->join('media','cat_media.id_media=media.id_media','left outer')
->where('cat.id_parent',$id_cat) //comes from function
->where('cat_lang.lang',$lang)
$query = $this->db->get();
I will filter the big images after then with:
$sub_cats = $query->result_array();
$data['sub_cats']= array();
foreach($sub_cats as $key => $value)
{
if($value['usage'] == 'base' OR $value['usage'] == null)
$data['sub_cats'][] = $value;
}
$value['usage'] == null is where the trouble begins. Problem is in some categories, there is not attached base image and above query does not return this categories because it did not match in cat.id_cat= cat_media.id_cat condition.
I want to get in result table:
id_cat:1 , ..., id_media = 2, usage=big
id_cat:2 , ..., id_media = null, usage=null
So I need them in the result table as null. How can I do that? Stacked here for hours. Thanks for any help..
I realized that I am trying something which is not possible.
Trying to get categories which has image attached, but also asking which are no image attached as well. I make sure that while creating a category I am attaching a default no-preview image now, now query does the job. Thanks for answers.