peter_anderson Posted December 5, 2010 Share Posted December 5, 2010 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 https://forums.phpfreaks.com/topic/220745-need-help-with-logic/ Share on other sites More sharing options...
Psycho Posted December 5, 2010 Share Posted December 5, 2010 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 https://forums.phpfreaks.com/topic/220745-need-help-with-logic/#findComment-1143245 Share on other sites More sharing options...
peter_anderson Posted December 5, 2010 Author Share Posted December 5, 2010 Hi, There is an if statement, depending on which the Get variable 'offer' is set as. The variable for the number of points is $remove_points. Thanks for the proper way to do the sum Link to comment https://forums.phpfreaks.com/topic/220745-need-help-with-logic/#findComment-1143246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.