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
https://forums.phpfreaks.com/topic/262851-help-with-mysql-update/
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    |

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.