Jump to content

how do i join these querys together. please help


advo

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.