为什么mysql_fetch的和值增加了一倍?

时间:2016-04-11 05:16:45

标签: mysql fetch

我有一个2个数据库。

1为game_jnship_user,2为game_jnship_equip,数据如下:

以下是game_jnship_user

+-----+-----------------+
| ID  | uid             |
+-----+-----------------+
| 1   | 50              |
+-----------------------+

以下是game_jnship_equip

+-----+------------+---------------+--------------+
| ID  | uid        | ebonus        | etype        |
+-----+------------+---------------+--------------+
| 1   | 50         | 100           | 1            |
| 2   | 50         | 10            | 1            |
| 3   | 50         | 120           | 2            |
+-------------------------------------------------+

我查询如下:

$_G['uid'] = '50';
$ushuxing = DB::query("SELECT sum(t2.ebonus) AS equipatk, sum(t3.ebonus) AS equipdef FROM ".DB::table('game_jnship_user')." t1 LEFT JOIN ".DB::table('game_jnship_equip')." t2 ON (t1.uid = t2.uid AND t2.etype = '1') LEFT JOIN ".DB::table('game_jnship_equip')." t3 ON (t1.uid = t3.uid AND t3.etype = '2') WHERE t1.uid = $_G[uid]");
$rushuxing = DB::fetch($ushuxing);

之后,我的输出数据如下:

$rushuxing[equipatk] = 110;
$rushuxing[equipdef] = 240;

为什么$rushuxing[equipdef]输出240不是120

谢谢。

以下是上例中的原始MySQL查询:

SELECT sum(t2.ebonus) AS equipatk, sum(t3.ebonus) AS equipdef
FROM game_jnship_user t1
LEFT JOIN game_jnship_equip t2
    ON (t1.uid = t2.uid AND t2.etype = '1')
LEFT JOIN game_jnship_equip t3
    ON (t1.uid = t3.uid AND t3.etype = '2')
WHERE t1.uid = '50'

0 个答案:

没有答案