title: back-Updating tree of rows in DB from result of last update
body: <p>I'm not sure this is even possible, but I would really like to be sure in order to create the most efficient code...
  I need to build a query that works like an affiliate - 
  when a user signs in, I need to see if someone invited him, or if he got there alone (basic URL param). If he was invited, I need to give him X points. If the inviter was invited by someone, I need to give him 1/2X points, and if he was also invited, I need to give his inviter 1/4 points.  I need this to be endless until the parent of all has no more "invited_by" values (null/0)...</p>
  
  <p>I did this with a php (while x), a counter to calculate the amount of points - 1/(X sqr $i), but i'm not happy because it takes me a select and update query each time...</p>
  
  <p>I'm using php and mysql.
  Is there someone who can think of a better way to do this?
  Thanks!</p>