Jump to content

Adding


me102

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.