user_id | user_referral_number | email | first_name | last_name | referral
when a user signs up, they get a referral number assigned to them, the best way to do it is probably make their user_referral_number a md5 or some sort of encrypted version of their email, sha1 is very long. OR you could just generate random letters and numbers... whatever suits your fancy. Either way you go about it you should always be checking to make sure that each string is unique. If someone is referred by another person when they sign up that persons user_referal_number OR user_id (which is my preferred method) in the referral column. To check something like that would be really simple too
now this is assuming $userid is set to to read the user_id from some sort of $_POST, $_GET OR $_SESSION
$result = mysql_query( "SELECT referral FROM users WHERE referral = $userid" );
echo mysql_num_rows( $result );
Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.