我有这段代码,用于存储 table_2013
列总计的总和并将其存储到 $total2013
。现在我想回显总和,并且还想回显 total2013
的总和加上 total2014
的总和,而不是打印我得到的总和
"Resource id #4"
$t2013 ="SELECT SUM(total) FROM table_2013";
$total2013 = (mysql_fetch_assoc($t2013));
$t2014 ="SELECT SUM(total) FROM table_2014";
$total2014 = (mysql_fetch_assoc($t2014));
echo "$total2013";
echo "$total2014";
echo "$total2013 + $total2014";
最佳答案
您没有执行查询。执行它们 -
$t2013 ="SELECT SUM(total) FROM table_2013";
$total2013 = (mysql_fetch_assoc(mysql_query($t2013)));
$t2014 ="SELECT SUM(total) FROM table_2014";
$total2014 = (mysql_fetch_assoc(mysql_query($t2014)));
您还需要提供列名称 -
echo $total2013['SUM(total)'] + $total2014['SUM(total)'];
关于php - Mysql为变量赋值并回显它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31692520/