Unrelated to your prime objective but I would scratch the die method that you use. By showing the SQL query, you are revealing your database schema to the end user. Instead you should just show the mysql_error that is a text portion at a redirect page. So you could create a generic error page that transmits the error code by errorpage.php?error=$sqlerrormsg.
Back to your main issue. To eliminate duplicate work, I would compact it into a function like.
queryFriends($id, $status)
{
$sqlquery = 'SELECT * FROM `friends` WHERE `user_id`= "'.$id.'" AND `status`="'.$status.'"';
$sqlresult = @ mysql_query($sqlquery,$connection) || die('however you want to do this');
$row = mysql_fetch_array($sqlresult)
$queryids[0] = $row['userid_1'];
$queryids[1] = $row['userid_2'];
return $queryids;
}
Then you could call it like...
$friends_pending = queryFriends($id, "1");
$friends_approved = queryFriends($id, "2");
As far as the many else if statements, I would use a switch statement instead since this will trim down on excessive code. I would help out with the later part of the code but I am really tired and am having a hard time backtracking what id1-4 means. For my sake, could you rename the id variables to words instead of numbers so I can understand it easier? I will in return show you how I would do it if that helps. A little background on what the fields in the friends table are would help too.