PHP / MySQL根据以前的if语句输出指定的字段

If $userid equals $row['RequestRecipientID'] then the script will output all $row['StatusType'] which equals "Accepted". What I'm needing for this script to do is only output the $row['StatusType'] which equals to the $userid. Any ideas?

<?php
include("enc.php");
mysqlcon();
$userid = $_SESSION['userid'];
$results = mysql_query("SELECT requests.RequestRecipientID, requests.StatusType, requests.AddedMessage, requests.FriendType, requests.RequestSentByID, requests.id, users.username, users.firstname, users.lastname, users.email, users.user_pid, users.id FROM requests, users");
while($row = mysql_fetch_array($results)) {
    if ($userid == $row['RequestRecipientID']) {
        if ($row['StatusType'] == "Accepted") {
        echo $row['firstname'] . "has accepted your friend request."; // place inside  notification pane
    } elseif ($row['StatusType'] == "Denied") {
        echo $row['RequestSentByID'] . " has denied your request.";
    } elseif ($row['StatusType'] == "Pending") {
    echo "<span class='text1'>";
    echo $row['firstname'] . " " . $row['lastname'] . "<br>" . $row['AddedMessage'] . "</span>";
    echo "<form method='GET' action='protected/process-friend-request-action.php?" . $row['id'] . "'>";
    echo '<input class="action_button" name="accepted" type="submit" value="Accept" />';
    echo '<input class="action_button" name="denied" type="submit" value="Deny" />';
    echo '<input type="hidden" name="id" value="' . $row["id"] . '" />';
    echo '</form>';
    }
    }
}
?>

If you only need results that is related to a userid you should first filter using SQL query.

// Assuming that your SQL query is correct
// added WHERE users.RequestRecipientID = '$userid'
$results = mysql_query("SELECT requests.RequestRecipientID, requests.StatusType, requests.AddedMessage, requests.FriendType, requests.RequestSentByID, requests.id, users.username, users.firstname, users.lastname, users.email, users.user_pid, users.id FROM requests, users WHERE users.RequestRecipientID = '$userid'");

// used fetch_assoc instead of fetch_array since you are 
// not using numeric array
while($row = mysql_fetch_assoc($results)) {
    // normally 3 is my limit to use if-else
    // if i have more than 3, i'll use switch
    if ($row['StatusType'] == "Accepted") {
        // accepted action
    }
    elseif ($row['StatusType'] == "Denied") {
        // denied action
    }
    else {
        // not denied & accepted action
    }
}

A few things to start.

First, read, learn and love MySQL Joins - Coding Horror: MySQL Joins

You seem to have gotten confused between RequestRecipientID and RequestSendByID (for my solution, I have assumed you are wanting to see all Request sent by, or sent to, the current user.

You really need to test for errors whenever you interact with a database. Failing to test for errors is just asking for stuff to break without explanation.

<?php

include( 'enc.php' );
mysqlcon();

$userid = $_SESSION['userid'];
$sqlStr = 'SELECT
             `r`.`RequestRecipientID`, `r`.`StatusType`, `r`.`AddedMessage`, `r`.`FriendType`, `r`.`RequestSentByID`, `r`.`id` AS `requestID`,
             `other`.`username`, `other`.`firstname`, `other`.`lastname`, `other`.`email`, `other`.`user_pid`, `other`.`id` AS `otherID`
           FROM `request` AS `r`
             LEFT JOIN `users` AS `other` ON ( IF( `r`.`RequestRecipientID` = '.(int) $userid.' , `r`.`RequestSentByID` , `r`.`RequestRecipientID` ) = `user`.`id` )
           WHERE
             '.(int) $userid.' IN ( `r`.`RequestSentByID` , `r`.`RequestRecipientID` )';

$results = mysql_query( $sqlStr );

if( !$results ){
  // There was an error in the SQL Query
}elseif( mysql_num_rows( $results )==0 ){
  // No Records were returned
}else{
  while( $r = mysql_fetch_array( $results ) ){
    if( $r['RequestSentByID']==$userid ){
      // A Request Sent by the Current User
      switch( strtolower( $r['StatusType'] ) ){
        case 'accepted' :
        case 'denied' :
          echo $r['firstname'].' has '.strtolower( $r['StatusType'] ).' your friend request';
          break;
        case 'pending' :
          echo $r['firstname'].' has not yet responded to your friend request';
        default:
          echo 'This Request has an unexpected Status of '.strtolower( $r['StatusType'] );
      }
    }else{
      // A Request Sent to the Current User
      switch( strtolower( $r['StatusType'] ) ){
        case 'accepted' :
        case 'denied' :
          echo 'You '.strtolower( $r['StatusType'] ).' a friend request from '.$r['firstname'];
          break;
        case 'pending' :
          echo '<span class="text1">'.$r['firstname'].' '.$r['lastname'].'<br>'.$r['AddedMessage'].'</span>';
          echo '<form method="get" action="protected/process-friend-request-action.php">';
            echo '<input class="action_button" name="accepted" type="submit" value="Accept" />';
            echo '<input class="action_button" name="denied" type="submit" value="Deny" />';
            echo '<input type="hidden" name="id" value="'.$r['requestID'].'" />';
          echo '</form>';
        default:
          echo 'This Request has an unexpected Status of '.strtolower( $r['StatusType'] );
      }
    }
  }
}