I have this code:
<?php
$con = mysql_connect(DB_HOST, DB_USER, DB_PASS);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db(DB_NAME, $con);
$result = mysql_query("SELECT SUM(colname) FROM profits");
$total = reset (mysql_fetch_assoc($result));
mysql_close($con);
echo $total;
?>
And its outputting an Resource id #5. Any help? Thanks in advance!
You're trying to echo an associative array with
echo $total;
. Instead just echo the first (and probably only based on your query) item.Don't use
reset()
like that - if you need a single value, just uselist()
:reset()
does not work as you expect on associative arrays: https://bugs.php.net/bug.php?id=38478