问题描述
我在 PHP 中运行以下查询:
I have the following query running in PHP:
$ticketTotal = mysql_query("SELECT SUM(`tickets_issued`) FROM `tb_att_registered_attendants` WHERE `confirmation_code`!='000000'");
但是当我返回 $ticketTotal 时,我得到 Resource id #33 并且当我转储变量时,我得到 resource(33) 类型(mysql结果).当我在 phpMyAdmin 中运行完全相同的查询时,我得到了正确的结果.我似乎在谷歌上找不到太多东西.怎么回事?
But when I return $ticketTotal, I get Resource id #33 and when I dump the variable, I get resource(33) of type (mysql result). When I run the exact same query in phpMyAdmin, I get the correct result. I can't seem to find much on google. What is going on?
提前感谢您的帮助.
推荐答案
$ticketTotal 不保存您的查询结果.您仍然必须实际获取它们.
$ticketTotal doesn't hold your query results. You still have to actually fetch them.
while ($row = mysql_fetch_assoc($ticketTotal))
{
print_r($row);
}
请不要在新代码中使用 mysql_* 函数.它们不再被维护并被正式弃用.看到 红框?改为了解 准备好的陈述,并使用 PDO 或 MySQLi- 这篇文章将帮助你决定哪一个.如果您选择 PDO,这里有一个很好的教程.
Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.
这篇关于MySQL SUM 查询问题 php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)