0

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.

lampwins
  • 920
  • 1
  • 9
  • 25

3 Answers3

1

$ticketTotal doesn't hold your query results. You still have to actually fetch them.

while ($row = mysql_fetch_assoc($ticketTotal))
{
    print_r($row);
}

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.

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • So is there an easier way to update an old application that has around 5k queries running across about 200 different files? – lampwins Jan 13 '13 at 01:16
0

If you are not using PHP5.5.0, then you can use below way, since mysql_result is deprecreated as of PHP5.5.0

$result = mysql_query("SELECT SUM(`tickets_issued`) FROM `tb_att_registered_attendants` WHERE `confirmation_code`!='000000'");
$ticketTotal = mysql_result($result,0);
Vinodkumar SC
  • 323
  • 2
  • 15
0

You can use this solution:

$Row = mysql_fetch_array($ticketTotal);
$sum = $Row['SUM(tickets_issued)'];

I have tested it for my code and it works properly.

zavg
  • 10,351
  • 4
  • 44
  • 67
mgh
  • 1
  • 1