循环使用php表

i'm making a table on my website where data is pulled out of my database.

Basically what i want it to do is to check for the column where the referrer is $session and on that same row it will look for the column 'username' and it will echo the username column into the table onto the website.

What im doing is a refer a friend system but basically you can view the people you referred, so when you referred someone it would insert your name '$session' into the referrer column and now i just need it to grab that out of the database so people can see who they referred 'username' column.

Sorry for the confusing wording.

Code here

http://pastebin.com/rhYvtA2L

lets say try this

   $my_array;
  while_loop(){
    if session == $row['Referrer']
     array_push($my_array,'your value');

    }

How about limiting the MySQL query with a WHERE clause involving the value of $session? As in

$query = "SELECT * from refer WHERE Referrer='". $session . "'";
$result = mysql_query($query);

Then just loop over the results - you know they are all the people referred by the person whose ID is in $session because of the query.