Jump to content

Help with MySQL update?


ffxpwns

Recommended Posts

So there is this code I have here :  http://pastebin.com/rwcN7FeJ and I need to find a way to incorporate this code that user Barand gave me

$referName = mysql_real_escape_string($gateway_data['refer']);
$query = "UPDATE users a
        INNER JOIN users b ON a.refer = b.nick
        SET a.refer = '', b.balance = b.balance + 5
        WHERE b.refer = '$referName'";
mysql_query($query);

 

But I havent the damnedest how to do that.  If anyone could help me at all, it would be appreciated.

Link to comment
Share on other sites

I must add, my table structure has columns called 'nick' (username) 'refer' (Who referred this person) and 'balance'  There are a lot of other ones, but these are the ones that matter.  So when someone signs up, they put in their referrers username and it does nothing.  And when the referred user buys something, the referrer gets 5$.  Here is my question.  How would I write an UPDATE where the name in the refer field would award the referrer with +5 to balance, then it would clear the 'refer' field.  I got the set refer to blank. 

 

Like this:

+------+-------+------------+

| nick  | refer | balance    |

+------+-------+------------+

|  A    |  B      |  0.00      |

+------+-------+------------+

|  B    |  C      |  0.00      |

+------+-------+------------+

 

 

A buys so B gets $5 added to his balance and the referrer is cleared from A, giving this after the update

 

 

+------+-------+------------+

| nick  |  refer | balance    |

+------+-------+------------+

|  A      |        |    0.00    |

+------+-------+------------+

|  B    |    C    |    5.00    |

+------+-------+------------+

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.