/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Find the sum of two mysql returns

I have an Admin chart which displays the activities of the users. One of the fields my client is asking for is a total number of securities purchased. Don’t worry what I’m talking about when I say securities purchased, sometimes I wonder what it really means. (ooooooo…)

The sum should come from the Database Table “users”. I want to be able to add all of the securities purchased (secpurch) together for a total. The only way I can think of it is like this:

[code=php]

if($id == 1) {
$secpurch1 = $row[‘secpurch’];
}
if($id == 2) {
$secpurch2 = $row[‘secpurch’];
}

//and so on…

$secpurchsum = $secpurch1 + $secpurch 2 + … ;

echo $secpurchsum;
[/code]

Obviously this is not a very intelligent way of accomplishing this.

Does anyone have any better ideas?

Thanks You!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordMay 28.2008 — if all the securities purchased are in a database table you could use something like this:

http://www.tizag.com/mysqlTutorial/mysqlsum.php
Copy linkTweet thisAlerts:
@Design-is-BSauthorMay 28.2008 — Thanks a lot Phil, it worked!

[code=php]
<?php
$result = mysql_query("
SELECT SUM(secpurch) FROM users
");

while ($row = mysql_fetch_array($result)) {

echo $row['SUM(secpurch)'];

}
?>
[/code]


Cheers
×

Success!

Help @Design-is-BS spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...