Ok lets say I’m making a social networks like twitter.
I have a table called social where it gets or where we put our social thing.
example me ( uid = 1 )
friend1 ( uid = 2 )
friend2 ( uid = 3 )
The table
SID AUID BUID
1 1 2
2 1 3
3 2 1
The information that we get here is
user id 1(me) is following 2
user id 1(me) is following 3
user id 2 is following 1(me)
And the question is: Can we do something like the two queries below in one single query ?
function CountFollowers($uid){
$count = $this->fetch("SELECT COUNT(BUID) as followers
FROM social WHERE BUID = :uid",
array( 'uid' => $uid));
return $count;
}
and
function CountFollowing($uid){
$count = $this->fetch("SELECT COUNT(AUID) as following
FROM social WHERE AUID = :uid",
array( 'uid' => $uid));
return $arrayofdata;
}
Thanks for looking in
This gets you two columns with the count of following and followers