Newbie in the house. Let me quickly tell you what I am trying to attempt and then hopefully you can help me clear this up. It may be a logic issue, I simply don’t know as there is no error. It just does not work.
I have a database full of users. Each user is referred by someone else. Members have the ability to become vip. If the member above you is not a vip, this script is meant to “walk” the records until it finds the first vip in the chain of users that are directly linked to you. Entity relationship if you will.
I am passing in the referralid of the user that referred the user that is logged in. The script will pull the user record that belongs to the person who referred the logged in user. If the referrer is not a vip, it will then identify who referred the referrer and check for vip status and so on and so forth. the referral_id will always be the username of the person that referred you.
[php]function getVIP($referralid=NULL)
{
global $db,$db_table_prefix;
$vip = 0;
while ($vip = 0)
{
if($referralid!=NULL)
{
$sql = “SELECT * FROM “.$db_table_prefix.“Users
WHERE
username = '”.$db->sql_escape(sanitize($referralid)).”’
LIMIT
1”;
}
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
if($row[“vip”] == 0)
{
$referralid = $row[“referral_id”];
$vip = $row[“vip”];
}
else
{
$vip = $row[“vip”];
}
}
return ($row);
}
[/php]