There is a score link table that holds a list of item_ids, the category_ids they are assigned to, and a score.
What I am trying to do is For each category, grab all the items assigned to it, ordered by highest score first. This then defines that items RANK ORDER in that category.
I then want to store that items RANK in the same table against the matching item_id and category_id.
This works great with the PHP MySQL code i have, but unfortunately there are 10000 categories and so takes about 30mins before timing out.
Here is an example of what im doing:
SELECT category_id FROM tbl_categories /* - this just grabs a list of categorys to loop through */
Loop through each row returned {
SELECT item_id, score
FROM tbl_scores
WHERE category_id = CATEGORY_ID ORDER BY score DESC
MYCOUNT = 0
Loop through each results, incrementing the count and storing in another tables {
MYCOUNT = MYCOUNT + 1
UPDATE tbl_scores
SET rank = MYCOUNT
WHERE item_id = ITEMID AND category_id = CATEGORYID
}
}