I have the following query running in PHP:
$ticketTotal = mysql_query("SELECT SUM(`tickets_issued`) FROM `tb_att_registered_attendants` WHERE `confirmation_code`!='000000'");
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?
Thanks in advance for any help.
解决方案
$ticketTotal doesn't hold your query results. You still have to actually fetch them.
while ($row = mysql_fetch_assoc($ticketTotal))
{
print_r($row);
}
PHP查询问题:为何$ticketTotal资源类型错误?解决办法
博主在PHP中运行SQL查询获取票务发行总和,但在返回时得到mysql_result资源,而非预期结果。在phpMyAdmin能得到正确答案。文章探讨了问题原因并提供了解决方案,即通过mysql_fetch_assoc获取查询结果。
176

被折叠的 条评论
为什么被折叠?



