Hi there, me again, got another SQL question. I’m having ago at trying to create a little tagging system. Still learning php+mysql so hopefully you can help me out.
My system at the moment is that I have a drop down menu where you select a category/tag and then that id and name gets inserted into a table named ‘cr_entry’.
Those ids and names are pulled from another table named ‘cr_cat’ and what I need to do is COUNT how many rows have the same id and name in ‘cr_entry’ as the chosen category/tag and then that number gets inserted into a new column named ‘count’ in ‘cr_cat’ so i.e. it the data in the row would be 4, 3, 10 and so on.
I know this requires the COUNT function, but I’m not sure how to go about it, or is it even possible?
My Setup/Idea: -
In ‘cr_entry’ I have various other columns and rows, but I have by categories/tags setup as 'cat_id | cat_id2 | cat_id3 | cat_id4 (which are INTERGERS) If that makes any sense?
So I guess what needs to be done is i.e. look in column ‘cat_id’ (FROM ‘cr_entry’) look for an id that corresponds to that of in table ‘cr_cat’ i.e. ‘id 4’ COUNT how many 4s there are in ‘cr entry’ column ‘cat_id’ and insert that number into column ‘count’ in table ‘cr_cat’ in row 4 (for id 4 etc), where there could be i.e. 15 rows with that id, so insert that number and so on for the other ids and then go into cat_id2, cat_id3, cat_id4 and do the same.
Might be the wrong way, I had ago at doing the a bit of SQL for it, but I’m still quite crap at it lol. I’m still having ago, but it’s trial and error and nothing seems to be happening.
Or if anyone can recommend a better solution, that would be great
Any advice would be greatly appreciated,
thank you.
EDIT: - Just found this, ’ having a quick glance, it might be helpful
http://www.webdevelopersnotes.com/tutorials/sql/online_mysql_training_course_counting.php3
I’ll let you know how I get on, but if you have any ideas too, that would help