php字段统计求和
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 13:10:30
0
2
489

问题是:现在需要统计表table中的num字段全部数据和,并且输出该总值。
统计可以用select sum(num) from table这条sql语句执行,但是问题在于不知道怎么把最终结果读出来???有大神指教吗??

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
Peter_Zhu

Try setting an alias for the result and you will be able to check it out

$sql = 'select sum(num) AS the_result from table';
$r = $db->query($sql);
$r['the_result']; // 想要的结果
巴扎黑
$updataquery = "select  sum(lv) AS the_result from gti_enews_technology_group" ;
$r=$empire->fetch1($updataquery);
print_r($r);


//打印的结果是Array ( [0] => 252 [the_result] => 252 )

The one upstairs should be fine

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!