I have two functions and i want to make it like one.
function 1
public function getAlliancesList($pageIndex, $pageSize)
{
return $this->provider->fetchResultSet("SELECT a.id, a.name, a.player_count, a.rating FROM p_alliances a ORDER BY a.rating DESC, a.player_count DESC, a.id ASC LIMIT %s,%s", array($pageIndex * $pageSize, $pageSize));
}
function 2
public function getAllianceAverage($allianceId)
{
$row = $this->provider->fetchRow("SELECT AVG(p.total_people_count) as average FROM p_players p WHERE p.alliance_id = '%s'", array($allianceId));
return intval($row['average']);
}
Basically I want to join function 2 into function 1 so I don’t need 2 query’s and I can then call that one function on the template file like $this->datalist->row['average'] if this is even possible.
I’ve tried a lot of ways to get the two queries to work together but to no avail so any help would be great.
EDIT:
What i want is to include the alliance id in getAllianceList function
this is how we tried till now:
public function getAlliancesList($pageIndex, $pageSize)
{
return $this->provider->fetchResultSet("SELECT *
FROM `p_alliances`
JOIN `p_players`
ON `p_players`.`id` = `p_alliances`.`id` LIMIT %s,%s", array($pageIndex * $pageSize, $pageSize));
}
If there could be 0 players you might want to change
INNER JOINtoLEFT JOIN, but it may impact performance in mysql.