Here is my current code:
<?php
require('qs_connection.php');
require('qs_functions.php');
require('../config.php');
## Performing a query to determine the epic counts based on item type
$query="SELECT COUNT( fab_mc.epics ) epics,
mc_drop_garr.`id` gid
FROM `fab_mc` , `mc_drop_garr`
WHERE fab_mc.epics = mc_drop_garr.item
GROUP BY mc_drop_garr.item, mc_drop_garr.`id` ASC";
$result=mysql_query($query) or die(mysql_error());
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$drops=mysql_result($result,$i,"epics");
$id=mysql_result($result, $i, "gid");
$sql="UPDATE `mc_drop_garr`, `fab_mc` SET
`drop`='$drops'
WHERE fab_mc.epics=mc_drop_garr.item";
if ($sql_debug_mode==1) { echo "<BR>SQL: $sql<BR>"; }
$result = mysql_query($sql) or die(mysql_error());
$i++;
}
if ($result == 1) {
die ('<center>Garr dropped totals have been updated.</center>');
} else {
echo "Error with SQL and updating..";
}
?>
Here's what "should" be happening:
The search query finds all of the data from fab_mc.epics that equals the same name as mc_drop_garr.item and counts those up and groups them. It displays similar to:
1 -- 5
2 -- 2
3 -- 1
4 -- 6
5 -- 4
6 -- 3
etc. up to ID 13
The left hand column is the ID.
The right hand column are the grouped "dropped" counts.
I want to update the drop counts into mc_drop_garr.drop where they correspond to the ID.
However, I keep getting an invalid result resource for the following two lines:
$drops=mysql_result($result,$i,"epics");
$id=mysql_result($result, $i, "gid");
Can anyone let me know what I'm doing wrong and what I should be altering with my code to update these values?
Thanks!