本文介绍了资源ID#4 PHP MYSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    $result = mysql_query("SELECT indvsum.sum1 + indvsum.sum2
    FROM (SELECT SUM(Cash) AS sum1,
                 SUM(Bank) AS sum2
          FROM players) indvsum");

    echo $result;

由于某种原因,这将返回资源ID#4.

For some reason this is returning Resource id #4.

如何获取sum1 + sum2的返回结果?

How do I get the results of sum1 + sum2 returned?

推荐答案

由于 $result 是一个数组,因此返回了资源ID#4.

Resource id #4 is being returned because $result is an array.

例如:

$q_example = "SELECT indvsum.sum1 + indvsum.sum2 AS `aSUM`
                  FROM (SELECT SUM(Cash) AS sum1, SUM(Bank) AS sum2 FROM players) indvsum";
$rsexample = mysql_query($q_example, $DB) or die(mysql_error());
$row_rsexample = mysql_fetch_assoc($rsexample);

echo $row_rsexample['aSUM'];

...应该为您提供所需的东西.

...should get you what you are looking for.

这篇关于资源ID#4 PHP MYSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:31