Skip to content

Instantly share code, notes, and snippets.

@dongilbert
Forked from drmmr763/chapter.php
Last active December 10, 2015 17:49
Show Gist options
  • Save dongilbert/4470755 to your computer and use it in GitHub Desktop.
Save dongilbert/4470755 to your computer and use it in GitHub Desktop.
Moved the query from the loop into a sub query and then optimized a little.
<?php
public function getSubmits()
{
$cid = JFactory::getApplication()->input->getInt('cid');
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select('a.*, i.username');
$query->select('(SELECT SUM(v.vote) FROM #__rootflick_vote AS v WHERE v.sub_id = a.id) AS vote');
$query->from('#__rootflick_submissions as a');
$query->leftJoin('#__users as i ON (a.user_id = i.id)');
$query->where('chapter_id='.$cid . ' and winner = 0');
return $db->setQuery($query)->loadObjectList();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment