<?php
require('qs_connection.php');
require('qs_functions.php');
require('../config.php');
## Performing a query to find all the ingredients of the ZG loot system, including the
## event days where the names match up for both tables
$coincount = "
SELECT COUNT(c.trade) trade,
COUNT(c.recipe) recipe,
COUNT(c.rares) rares,
COUNT(c.epics) epics,
b.name name, b.class class, b.guid bGuid,
c.guid cGuid, b.ed_mc events, c.trade loot4,
c.rares loot5, c.epics loot6, c.recipe loot7
FROM `fab_total` AS b
INNER JOIN `fab_mc` AS c
ON b.guid=c.guid
GROUP BY b.name, b.guid ASC";
$coinresult = mysql_query($coincount);
$num=mysql_numrows($coinresult);
$i=0;
while ($i < $num) {
$name=mysql_result($coinresult,$i,"name");
$class=mysql_result($coinresult, $i, "class");
$guid =mysql_result($coinresult, $i, "bGuid");
// Now plug the variables for numbers of types of items gained
$common=mysql_result($coinresult,$i,"trade");
$recipe=mysql_result($coinresult,$i,"recipe");
$rares=mysql_result($coinresult,$i,"rares");
$epics=mysql_result($coinresult,$i,"epics");
// Now plug the variables for name types on loot
$loot4=mysql_result($coinresult,$i,"loot4");
$loot5=mysql_result($coinresult,$i,"loot5");
$loot6=mysql_result($coinresult,$i,"loot6");
$loot7=mysql_result($coinresult,$i,"loot7");
// Now plug the number of events
$events=mysql_result($coinresult,$i,"events");
// Now formalize the percentages for each item gained
$commoncip=round(((($common + 1)/$events) * 100),2);
$rarecip=round(((($rares + 1)/$events) * 100),2);
$recipecip=round(((($recipe + 1)/$events) * 100),2);
$epiccip=round(((($epics + 1)/$events) * 100),2);
$sql = print $epics & "<br>";
$result = mysql_query($sql);
$i++;
}
?>
The problem I have is this bit of code:
// Now formalize the percentages for each item gained
$commoncip=round(((($common + 1)/$events) * 100),2);
$rarecip=round(((($rares + 1)/$events) * 100),2);
$recipecip=round(((($recipe + 1)/$events) * 100),2);
$epiccip=round(((($epics + 1)/$events) * 100),2);
It should find the item count for each row and add 1 to it and then devide by event days, multiply that by 100 for a percentage and round 2 places. However, it's not picking up the + 1 for some reason. As an example of what I'm getting is like this:
Person has 1 event day.
Person has 0 items.
Formula should read:
round((((0 + 1)/1) * 100),2); OR 100% instead it reads 0%.
Any ideas?
The issue is that it will calculate once it sees something in the count. If it doesn't, it doesn't do anything - just reads 0.
So if I add an item to each column under 1 ID, it updates correctly. If no item exists under any column for that userid, it does nothing. How can I force it to know if there's nothing counted, it should automatically read 1 count.