subhomoy Posted May 12, 2012 Share Posted May 12, 2012 hii everyone how to add the values of rows in a database.... I have added the code of my database table CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `money` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=23 DEFAULT CHARSET=utf8; And i have some rows like (1,peter, $94) (2,John,$16) .... .... .... .... .... i want to add those values (i.e their money) and shows like [ total money = $110]... I have done few queries like SELECT id,SUM(money) FROM users and mysql_query("SELECT * FROM `users` SUM `money` WHERE id='$id'"); But nothing seems to work out... Any help guysss.... Thanks in advance... Link to comment https://forums.phpfreaks.com/topic/262452-addition-of-rows-in-database/ Share on other sites More sharing options...
Barand Posted May 12, 2012 Share Posted May 12, 2012 just SELECT SUM(money) FROM users Link to comment https://forums.phpfreaks.com/topic/262452-addition-of-rows-in-database/#findComment-1345009 Share on other sites More sharing options...
subhomoy Posted May 13, 2012 Author Share Posted May 13, 2012 To Barand SELECT SUM(money) FROM users can you please tell me in detail.... I have done like this... <?php $raja = SELECT SUM(money) FROM users echo "$raja"; ?> But it shows an error.... if possible give the code... Link to comment https://forums.phpfreaks.com/topic/262452-addition-of-rows-in-database/#findComment-1345083 Share on other sites More sharing options...
Barand Posted May 13, 2012 Share Posted May 13, 2012 <?php $res = mysql_query("SELECT SUM(money) FROM users"); // send query to db server $row = mysql_fetch_row($res); // get first row from the resultset echo $row[0]; // echo first column of the row ?> I suggest you search for mysql tutorial. Link to comment https://forums.phpfreaks.com/topic/262452-addition-of-rows-in-database/#findComment-1345089 Share on other sites More sharing options...
subhomoy Posted May 15, 2012 Author Share Posted May 15, 2012 To Barand <?php $res = mysql_query("SELECT SUM(money) FROM users"); // send query to db server $row = mysql_fetch_row($res); // get first row from the resultset echo $row[0]; // echo first column of the row ?> Thanks it really helpsss....... Thanks once again.. Link to comment https://forums.phpfreaks.com/topic/262452-addition-of-rows-in-database/#findComment-1345525 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.