advo Posted December 29, 2011 Share Posted December 29, 2011 i have two functions but i want to make it into one function 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 on view file $this->datalist->row['average'] if this is even possible i've tried alot of ways to get the two wuerys to work together but to no avail so any help would be great. im sure some pro here can make this work Quote Link to comment https://forums.phpfreaks.com/topic/254003-how-do-i-join-these-querys-together-please-help/ Share on other sites More sharing options...
Muddy_Funster Posted December 29, 2011 Share Posted December 29, 2011 you would want something along the lines of: "SELECT p_alliances.id, p_alliances.name, p_alliances.player_count, p_alliances.rating AVG(p_players.total_people_count) as `average` FROM p_alliances LEFT JOIN p_players ON (p_alliences.id = p_players.allience_id) ORDER BY p_alliances.rating DESC, p_alliances.player_count DESC, p_alliances.id ASC LIMIT %s,%s", array($pageIndex * $pageSize, $pageSize) I doubt it's what you want, but it should give you enough to work with. Quote Link to comment https://forums.phpfreaks.com/topic/254003-how-do-i-join-these-querys-together-please-help/#findComment-1302155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.