Results 1 to 2 of 2
Thread: Table name stored in column
Sep 18, 2007, 05:28 #1
- Join Date
- Mar 2005
- 0 Post(s)
- 0 Thread(s)
Table name stored in column
Is there a way to solve the following problem with mysql only?
I have a tags table
CREATE TABLE `tags` ( `id` int(11) NOT NULL auto_increment, `tag` varchar(255) default NULL, `quicklink` varchar(255) default NULL, `related_table` varchar(255) default NULL, `related_id` int(11) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Now i want to generate a tagCloud, therefor i have the following query which works perfectly.
SELECT t.tag, t.quicklink, COUNT(t.tag) AS cnt FROM tags AS t GROUP BY t.tag
How can i limit the tagcloud query to only count tags of which the related item in the related table has status 1?
Thanks for any help on this one!
Sep 18, 2007, 05:59 #2
- Join Date
- Jul 2002
- Toronto, Canada
- 63 Post(s)
- 3 Thread(s)
my advice: never store the name of a table or column in your own table
i would completely redesign what you're doing
there would still be one tags table, but where you have people, buildings, and vehicles tables, you would then also have peopletags, buildingtags, and vehicletags tables to represent the many-to-many relationships