You have two issues:
$r
contains the resource ID for your MySQL connection. You echo it out. That's why you see that. Stop doing that and it goes away.
You are not using the right array key to access your sum value you seek so nothing is output. If you had error reporting turned out PHP would have told you this.
Here's improved code to resolve these issues:
<?php
$r=mysql_query("select sum(total_amount) as total from lbc_production where link_id='C741_Link01' and execution_date BETWEEN '2014-12-01' AND '2014-12-31'");
$rows=mysql_fetch_assoc($r);
echo $rows['total'];
?>
I removed the line where you echo out the MySQL resource and added an alias to sum(total_amount)
which makes it easier to access via PHP. The alias is called total
which I use as the key to access that value from the $row
array.
FYI, you shouldn'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.