MySQL SUM查询问题的PHP [英] MySQL SUM query problems php

查看:124
本文介绍了MySQL SUM查询问题的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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) of type (mysql result).当我在phpMyAdmin中运行完全相同的查询时,我得到正确的结果.我似乎在Google上找不到很多.发生了什么事?

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_*函数.它们已不再维护并已正式弃用.看到红色框?了解有关 准备好的语句 的信息,并使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆