Greetings,
I was wondering if there was a way to speed up this process:
$id = '99';
$sqlcount = "SELECT COUNT(*) as num FROM items WHERE category = '$id'";
$resultcount = mysql_fetch_array(mysql_query($sqlcount));
$count = $resultcount['num'];
mysql_query("UPDATE categories SET count = '$count' WHERE id = '$id'") or die(mysql_error());
Basically what this does is selects category ids and then counts up the number of items within that category, pulls out the count so I can display it and then updates the count back into the database for other purposes.
My question is what is an efficient way to count the number of items within a category, store it’s value in a variable and update the count in the database in one query.
Thanks