title: Show relationship using two table JOIN, or use PHP functions?
body: <p>I'm making a micro-blogging website. The users can follow each other. I've to make stream of posts (activity stream) for the current user ( $userid ) based on the users the current user is following, like in Twitter. I know two ways of implementing this. Which one is better?</p>
  
  <p>Tables:</p>
  
  <p>Table: posts<br/>
  Columns: PostID, AuthorID, TimeStamp, Content</p>
  
  <p>Table: follow<br/>
  Columns: poster, follower</p>
  
  <p>The <strong>first way</strong>, by joining these two tables:</p>
  
  <pre><code>select `posts`.* from `posts`,`follow` where `follow`.`follower`='$userid' and 
  `posts`.`AuthorID`=`follow`.`poster` order by `posts`.`postid` desc
  </code></pre>
  
  <p><br/>
  The <strong>second way</strong> is by making an array of users the $userid is following (posters), then doing php implode on this array, and then doing where in:
  <br/><br/>
  One thing I'll like to tell here that I'm storing the the number of users a user is following in the `following` record of the `user` table, so here I'll use this number as a limit when extracting the list of posters - the 'followingList':
  <br/><br/></p>
  
  <pre><code>function followingList($userid){
      $listArray=array();
      $limit="select `following` from `users` where `userid`='$userid' limit 1";
      $limit=mysql_query($limit);
      $limit=mysql_fetch_row($limit);
      $limit= (int) $limit[0];
      $sql="select `poster` from `follow` where `follower`='$userid' limit $limit";
      $result=mysql_query($sql);
      while($data = mysql_fetch_row($result)){
          $listArray[] = $data[0];
      }
      $posters=implode("','",$listArray);
      return $posters;
  }
  </code></pre>
  
  <p><br/>Now I've a comma separated list of user IDs the current $userid is following.<br/><br/>And now selecting the posts to make the activity stream:<br/></p>
  
  <pre><code>$posters=followingList($userid);
  $sql = "select * from `posts` where (`AuthorID` in ('$posters')) 
  order by `postid` desc";
  </code></pre>
  
  <p><hr/>
  Which of the two methods is better?
  And can knowing the total number of following (number of users the current user is following), make things faster in the first method as it's doing in the second method?<br/>
  Any other better method?</p>