Samurai Legend Posted May 18, 2014 Posted May 18, 2014 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); Quote
KyleMassacre Posted May 18, 2014 Posted May 18, 2014 Select the sum(). You don't need the count() Quote
sniko Posted May 18, 2014 Posted May 18, 2014 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']); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.