Jump to content
MakeWebGames

Add Up Everything


Samurai Legend

Recommended Posts

Hello all, I just need help.

I am trying to find out how I can add up all the tickets each users have from the users total in one query?

So I can times it by how much the raffle prize is...?

If you know what I meant.

 

$query = $db->query("SELECT COUNT(`raffle_tickets`) ,
			 SUM(`raffle_tickets`) FROM `users`");
$amount = ($db->num_rows($query));

$payment_one = money_formatter($set['payment-one_raffle']*$amount);
Link to comment
Share on other sites

CREATE TABLE users (
 userid INT(11) NOT NULL auto_increment,
 raffle_tickets SMALLINT(3) NOT NULL DEFAULT 0,
 PRIMARY KEY (userid)
 );

INSERT INTO `users` (userid,raffle_tickets) VALUES
(1,1),
(2,5),
(3,17);

 

SELECT SUM(`raffle_tickets`) AS total_raffle_tickets FROM `users`

 

SQLFiddle

 

$query = $db->query("SELECT SUM(`raffle_tickets`) AS total_raffle_tickets FROM `users`");
$amount = $query->fetch_row(); //Is this correct for the mcc db class?

$payment_one = money_formatter($set['payment-one_raffle']*$amount['total_raffle_tickets']);
Link to comment
Share on other sites

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.   Paste as plain text instead

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