[eluser]Juan Velandia[/eluser]
Hello Everyone, I´ve been dealing with this for quite a while I have this function in a model wich joins two tables.
Code:
function get_section_articles()
{
$this->db->select('cms_article.name AS article_name');
$this->db->select('cms_article.url_article');
$this->db->select('cms_section.name AS section_name');
$this->db->select('cms_section.photo AS section_photo');
$this->db->select('cms_article.url_section');
/* $this->db->where('cms_section.placeholder','2' );*/
$this->db->from('cms_article');
$this->db->join('cms_section','cms_section.url_section = cms_article.url_section','right');
$query = $this->db->get();
$previous_section = null;
foreach($query->result() as $row):
if ($row->url_section != $previous_section)
{
if ($previous_section != null)
{
$results[] = $section;
}
$section = array();
$section['url_section'] = $row->url_section;
$section['section_name'] = $row->section_name;
$section['section_photo'] = $row->section_photo;
$section['articles'] = array();
$previous_section = $row->url_section;
}
$article = array();
$article['article_name'] = $row->article_name;
$article['url_article'] = $row->url_article;
$section['articles'][] = $article;
endforeach;
if ($previous_section != 0)
{
$results[] = $section;
}
return $results;
}
But when I try to get the data from the cms_section.placeholder=2 it gets only one section and it´s articles. In the database there are more than 3 sections with cms_section.placeholder=2. Any ideas? thanks in advance