Jump to content

Recommended Posts

it certainly does

 

mysql> select colb from abc;
+------+
| colb |
+------+
| +10  |
| -100 |
| +45  |
+------+
3 rows in set (0.00 sec)

mysql> select SUM(colb) from abc;
+-----------+
| SUM(colb) |
+-----------+
|       -45 |
+-----------+
1 row in set (0.00 sec)

Link to comment
https://forums.phpfreaks.com/topic/108297-adding/#findComment-555387
Share on other sites

I've got this below - It was working when I just had one column. But when I added more columns, some had numbers in the signin and some didn't, it stopped working. Any idea?

 

$sumadd = mysql_query("SELECT SUM(signin) FROM `$table` GROUP BY `datecode`") or die(mysql_error());

while($row = mysql_fetch_array($sumadd)){extract($row);
echo "<center>Total Add for $choice = $signin";
echo "<br />";

Link to comment
https://forums.phpfreaks.com/topic/108297-adding/#findComment-559556
Share on other sites

There is no "signin" column in your result set. Use an alias for the SUM(signin)

 

<?php
$sumadd = mysql_query("SELECT SUM(signin) as signin FROM `$table` GROUP BY `datecode`") or die(mysql_error());

while($row = mysql_fetch_array($sumadd)){extract($row);
echo "<center>Total Add for $choice = $signin";
echo "<br />";

Link to comment
https://forums.phpfreaks.com/topic/108297-adding/#findComment-559560
Share on other sites

What datatype is the amount column?  Integer?  varchar?

 

If you don't know how to check, google it.

 

I'm guesing it's some kind of string type since you have a + or -...  (The + probably wouldn't be there if it were a numeric column... unless you're displaying it with modifications.)

 

If it is a string type, MySQL might not add the columns correctly.

Link to comment
https://forums.phpfreaks.com/topic/108297-adding/#findComment-560292
Share on other sites

Can someone tell me whats wrong with this?

 

 

<?php

$total = mysql_query("SELECT SUM(amount) as amount, FROM `transaction` WHERE `user_id` = '$user_id'") or die(mysql_error());
while($row = mysql_fetch_array($total)){
extract($row);

echo $amount;

}

?>

 

Syntax is wrong. Remove "," from before the "FROM"

Link to comment
https://forums.phpfreaks.com/topic/108297-adding/#findComment-560316
Share on other sites

Can someone tell me whats wrong with this?

 

 

<?php

$total = mysql_query("SELECT SUM(amount) as amount, FROM `transaction` WHERE `user_id` = '$user_id'") or die(mysql_error());
while($row = mysql_fetch_array($total)){
extract($row);

echo $amount;

}

?>

 

Syntax is wrong. Remove "," from before the "FROM"

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/108297-adding/#findComment-560385
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.