Let's say that I have a system of categories, tags and images where when creating a post, it is sent to my table of relations:
id, post_id, term_id, file_id, status, type.
Obviously when there is a value in the term_id, the type is basically a category or tag and the same with the file_id whose type is "media"; the status field is always 'attached'
I would just like to know if instead of doing this (example of the model I use to get the files_id type "media"):
public function getPostGallery($id){
$this->db->select('*');
$this->db->from($this->relationship);
$this->db->where('type', 'media');
$this->db->where('status', 'attached');
$this->db->where('post_id', $id);
$query = $this->db->get();
if($query->num_rows() >= 0){
return $query->result();
} else {
return false;
}
}
and this in the view:
<?php if($gallery): ?>
Has un foreach de type media
<?php endif; ?>
It was possible to do something like the following:
public function getPostGallery($id){
$this->db->select('*');
$this->db->from($this->relationship);
//$this->db->where('type', 'media');
$this->db->where('status', 'attached');
$this->db->where('post_id', $id);
$query = $this->db->get();
if($query->num_rows() >= 0){
return $query->result();
} else {
return false;
}
}
<?php if($gallery->type == 'media'): ?>
Has un foreach de type media
<?php endif; ?>
<?php if($gallery->type == 'tag') : ?>
Has un foreach de type tag
<?php endif; ?>
I do not know if I explain but thank you in advance.