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
Share on other sites

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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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