mysql - Sum of column in using mysqli and php -


i tring sum of column , show on page using code keeps returning "1" when should return "23" example. check sql statement , works fine. code using. (note: server iis php)

<?php require('connection.php');  $sql="select sum(amount) total td";  $result = mysqli_query($sql);  while ($row = mysqli_fetch_assoc($result)){ echo $row['total'];}  mysqli_close($con); ?> 

ok added while thing , breaks code white page.

i removed ! in mysqli_query , still white page, not sure if me or server not playing nice.

this may unrelated when removed ! mysqli_query other code broke it.

<?php require 'connection.php'; $date = $_post['date']; $comment = $_post['comment']; $amount = $_post['amount'];  $sql= "insert td (date, comment, amount) values ('$date', '$comment', '$amount')";  if (mysqli_query($con,$sql)) { die('error: ' . mysqli_error($con)); } echo "1 record added";  mysqli_close($con); ?> 

everything fixed everyone!!!

try this:

<?php require('connection.php');  $sql="select sum(amount) total td";  $result = mysqli_query($sql);  while ($row = mysqli_fetch_assoc($result)) {     echo $row['total']; }  mysqli_close($con); ?> 

as said in comment above, don't need ! infront of query method.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -