[eluser]emily12[/eluser]
After a lot of research I have found out that the solution to my problem exists with something called 'inner' instead of 'left' join. I had never heard of this before and wondered how this would work?
Code:
function get_featurednews() {
//////// TODO: Guarantee that it cannot be featured more than once
$this->db->select('b.user_id, b.username, p.narticleid, COUNT(*) AS votes, v.aid, v.vdate, p.news_type, p.full_url, p.l_title, p.author, p.l_desc, p.s_desc, p.m_thumb');
$this->db->from('table_news_articles AS p');
$this->db->join('table_news_votes AS v', 'v.aid = p.narticleid', 'inner');
$this->db->join('phpbb_users AS b', 'p.author = b.user_id', 'left');
$this->db->group_by('p.narticleid');
$this->db->where('p.time >=', date('Y-m-d H:i:s', time() - 86400 * 7)); // Past Week
$this->db->limit(8);
$query = $this->db->get();
return $query;
}
I'm more or less wondering how it works with an example so I could know for the future not to repeat this mistake and to better understand join. The given function won't work with 'inner' but it does with 'left' however $votes will display 1 as a minimum (see count) even though there's 0 vote results for that article.
Thank you! ^.^;