表中的和数并保存在变量中

I have table money in first row I have number 10 in second 20 and third 30 and now I'm going to sum this rows and save into variable $sum

This is my code

$result = mysql_query("SELECT SUM(money) as total FROM $tbl_name WHERE id='$idd'");
$row= mysql_fetch_array($result);
$sum= $row['total'];

If I print $sum Result is 102030 but I need to print 60

First of all, you have to change your table's structure.

alter table $tablename alter column money decimal(10,2)

Choose the decimal precision that fits your needs.

If you are really stuck because you do not have access to change the table structure, you could change your query to :

SELECT SUM(cast(money as decimal(10,2))) as total FROM $tbl_name WHERE id='$idd'