2

I am trying to get the sum of a whole column but it's not working.

What should i change in my code .

//error -> Warning: mysql_fetch_assoc() expects parameter 1 to be resource,
<?php
include("connect2.php");

$value = mysql_query("SELECT SUM(total) AS sum_total * FROM `posts` ") ;

$row = mysql_fetch_assoc($value);

$sum_total = $row['sum_total'];
?>
<div>
<a>
<?php echo  $sum_total; ?>
</a>

</div>
3
  • 1
    AS sum_total * what is * for? Commented Jan 23, 2017 at 20:28
  • what's the **** doing ? Commented Jan 23, 2017 at 20:28
  • 1
    Take the * out of the query. Also be aware that mysql_* functions are removed in PHP7 and deprecated in previous versions. It would be a good idea to switch to PDO or mysqli. Commented Jan 23, 2017 at 20:29

1 Answer 1

4

try without the *:

SELECT SUM(total) AS sum_total FROM `posts`
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.