-5

我有这个插入:

INSERT INTO gamecodes (gamecode, accountname, premium_points, alreadyused)
VALUES ('$gamecode','$accountorname',$premiumpoints,'N')

我需要帮助。在变量$accountorname中,我有一个 PLAYER 名称,我需要获取他的帐户。

两张表:

TABLE PLAYERS
id, name, account_id..
id, player name, table accounts.id

TABLE ACCOUNTS
id, name ..
id = table players account_id
4

2 回答 2

0

You could try something along the lines of:

INSERT INTO gamecodes (gamecode, accountname, premium_points, alreadyused) 
SELECT '$gamecode',accounts.name,$premiumpoints,'N' 
FROM accounts 
JOIN players
ON accounts.id = players.account_id 
WHERE players.name = '$accountorname'
于 2013-06-18T19:35:49.540 回答
0

您的查询可能类似于 -

INSERT INTO gamecodes( gamecode, accountname, premium_points, alreadyused) 
 VALUES('$gamecode', '$accountname', $premiumpoints, 'N')
 WHERE(SELECT accountname FROM accounts JOIN gamecodes ON accounts.accountname = gamecodes.accountname WHERE accounts.accountname = $accountname)
于 2013-06-18T19:33:44.443 回答