Jump to content

Need help with logic


peter_anderson

Recommended Posts

I have a file sharing script, where each file has a certain number of points. I need to subtract a set number of points from the total. I'm unsure about the logic of it.

 

This is how I total the number of points:

<?php
$fq = "SELECT * FROM `files` WHERE owner='$username' AND active=1";
$fw = $sql->query($fq);
$reward = 0;
while($fr = $fw->fetch_assoc()){
$reward = $fr['points'] + $reward;
}?>

 

I'm thinking I should use a loop, while a the number to subtract is greater than or equal than 0.

 

Can anyone help?

Link to comment
Share on other sites

You have not provided enough information. How are you determining how many points to subtract/ There may be a way to do it with a single query.

 

For example, you shouldn't even be using a loop to calculate the total

$fq = "SELECT SUM(points) as total FROM `files` WHERE owner='$username' AND active=1 GROUP BY owner";
$fw = $sql->query($fq);
$reward = 0;
$fr = $fw->fetch_assoc();
$total = $fr['total'];

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.