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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.