The below code updates category table and places the count of "0" where categoryg is null and the actual count of others in the category table.
I also need it to place a 0 in the category if there is none with the status of 1
If there is no categoryg with a status of one or null then place a 0 for a count..
Did i explaine this correct . I hope so.
$query3 = "SELECT categoryg, status, COUNT(*) AS count FROM subcat GROUP BY categoryg";
$result3 = mysql_query($query3) or die( "ERROR: " . mysql_error() . "\n");
while($row = mysql_fetch_array($result3)) {
$categoryg = $row['categoryg'];
$catcount = $row['count'];
$status = $row['status'];
print ("categoryg: $categoryg --- catcount: $catcount Status .... $status<br>");
$query4 = "UPDATE category SET count='$catcount' WHERE category='$categoryg'";
mysql_query($query4) or die( "ERROR: " . mysql_error() . "\n");
}
$sql = <<< EOSQL
SELECT c.category
FROM category c LEFT JOIN subcat s
ON c.category = s.categoryg
WHERE s.categoryg IS NULL
EOSQL;
$res = mysql_query($sql) or die ("Error: ".mysql_error());
while ($row = mysql_fetch_array($res)) {
$category = $row['category'];
print$sql = "UPDATE category SET count='0' WHERE category='$category'";
$res2 = mysql_query($sql) or die("Error: ".mysql_error());
}