![](/uploads/1/2/5/7/125735224/787524219.jpeg)
Tutorial kali ini kita akan membahas Cara Menjumlahkan data yang ada di database Mysql, data berbentuk numerik di database Mysql akan dengan mudah kita jumlahkan dengan Query SUM yang ada di mysql, untuk ini anda bisa lihat pada artikel Cara Menjumlahkan field data numerik di database, atau dijumlahkan berdasarkan tipe nya Menjumlahkan record / field numerik di database MYSQL, Namun terkadang. Menghitung Jumlah Harga dengan PHP dan Mysql, itu lah judul untuk hari ini tepatnya tanggal 11-agustus-2014, jam 17.23 wib, kondisi cuaca saat ini agak terasa panas (terang benderang).
Active3 years, 5 months ago
I'm new to php and I've searched for the past hour and read all the documentation I could find and nothing is helping. I have a table that has a bunch of rows of data. I'm trying to pick one column from the whole table and add them all together. Here is what I got. All this tells me is how many rows there are that match my query, not the total sum of column I want. Any help is appreciated.
JustinJustin
3 Answers
You're only returning one row in this instance. Modify your summed column to have an alias:
Now you can can fetch the row -
No need to loop.
Félix Gagnon-Grenier6,10588 gold badges4040 silver badges4949 bronze badges
Jay BlanchardJay Blanchard![Sum Sum](http://suckittrees.com/tinymce/gambar/image/PHP-MYSQL/jumlah.jpg)
36.7k1212 gold badges6060 silver badges102102 bronze badges
You can use
SUM()
without explicitely grouping your rows because if you use a group function in a statement containing no GROUP BY clause, it is equivalent to grouping on all rows.If however you want to use the
SUM()
function for something slightly more complicated you have to group your rows so that the sum can operate on what you want.If you want to get multiple sums in a single statement, for example to get the distance for all users at once, you need to group the rows explicitely:
This will return the sum of distances by user, not for all users at once.
Félix Gagnon-GrenierFélix Gagnon-Grenier6,10588 gold badges4040 silver badges4949 bronze badges
user3706926user3706926
Not the answer you're looking for? Browse other questions tagged phpmysqlpdo or ask your own question.
![](/uploads/1/2/5/7/125735224/787524219.jpeg)