Jump to content

Addition of rows in database...


subhomoy

Recommended Posts

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

  <?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.

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

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.