如何将这个PHP IF简化为MySQL WHERE?

I have PHP script works without problems, like this :

while($row4 = mysql_fetch_array($result4))
{
if (($row4['Username'] != 'root') && ($row4['ToUpline'] == 1)){
if (!(($row4['Username'] != $MyUsername) && ($row4['Private'] == 1))){

//some other scripts here...

}};

on the other hand, I already have WHERE conditon on MySQL command :

WHERE (NetworkTree.LeftNum <= $MyLeftNum AND NetworkTree.RightNum >= $MyRightNum) 
AND MyBlackList.HideWho IS NULL

how to combine these PHP conditions into 1 single SQL command so that I can remove PHP IF. thanks...

WHERE
  NetworkTree.LeftNum <= $MyLeftNum AND
  NetworkTree.RightNum >= $MyRightNum AND
  MyBlackList.HideWho IS NULL AND
  Username <> 'root' AND
  ToUpline = 1 AND
  NOT(Username <> 'myUsername' AND
      Private = 1)

How you fill in 'myUsername' above depends on how you are executing your query. Since you are using the outdated mysql_* functions you cannot use prepared statements, but you can use string concatenation or sprintf (don't forget to escape using mysql_real_escape_string!). Here's how to do it with sprintf:

$query = sprintf("SELECT ... WHERE ... NOT(Username <> '%s' ...)",
                 mysql_real_escape_string($username));
WHERE (NetworkTree.LeftNum <= $MyLeftNum AND NetworkTree.RightNum >= $MyRightNum) AND MyBlackList.HideWho IS NULL AND Username != 'root' AND ToUpLine = 1 AND NOT (Username != '$MyUsername' AND Private = 1)