HTML Tags DB structure
Moderator: General Moderators
HTML Tags DB structure
Hey All!!
I haven't been in a while but I'm looking to create a programming website which will have a reference page that contains all HTML tags. For example, if I click on the tag "a", the user goes to a second page which contains more details about the tag. That second page will contain the attributes of that tag (style, href, class...), it will contain the compatibility (HTML 4.0, HTML 3.2, MSIE, NS...). I would like all that info to be in a DB instead of creating all those pages. I'm just not sure of the structure.
My Tables:
Tag (contains all tags), fields: tagid, tagname, tagdesc
Attributes (contains all attributes for all tags), fields: attrid, attrname, attrdesc
Compatibility (contains all compatibility for all tags), fields: compid, compname
These are the tables I figured out I'll need.
How would I know which attribute goes with which tag? I know I can use their IDs but how would it work with multiple attributes for 1 tag?
Same for Compatibility table, how would I display all standards/browsers the tag is compatible with?
Is there a better way to do this?
Thx guys!
Chris
I haven't been in a while but I'm looking to create a programming website which will have a reference page that contains all HTML tags. For example, if I click on the tag "a", the user goes to a second page which contains more details about the tag. That second page will contain the attributes of that tag (style, href, class...), it will contain the compatibility (HTML 4.0, HTML 3.2, MSIE, NS...). I would like all that info to be in a DB instead of creating all those pages. I'm just not sure of the structure.
My Tables:
Tag (contains all tags), fields: tagid, tagname, tagdesc
Attributes (contains all attributes for all tags), fields: attrid, attrname, attrdesc
Compatibility (contains all compatibility for all tags), fields: compid, compname
These are the tables I figured out I'll need.
How would I know which attribute goes with which tag? I know I can use their IDs but how would it work with multiple attributes for 1 tag?
Same for Compatibility table, how would I display all standards/browsers the tag is compatible with?
Is there a better way to do this?
Thx guys!
Chris
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I know I should have "attrid" and "compid" in my tag table but how would I get multiple attributes for 1 tag from the attribute table same for compatibility table?
Lets say attrid=1 that could be "style" attribute. How can I get all attributes with only 1 attrid field?
Tag (contains all tags), fields: tagid, tagname, tagdesc, --> attrid, compid <--
Attributes (contains all attributes for all tags), fields: attrid, attrname, attrdesc
Compatibility (contains all compatibility for all tags), fields: compid, compname
Lets say attrid=1 that could be "style" attribute. How can I get all attributes with only 1 attrid field?
Tag (contains all tags), fields: tagid, tagname, tagdesc, --> attrid, compid <--
Attributes (contains all attributes for all tags), fields: attrid, attrname, attrdesc
Compatibility (contains all compatibility for all tags), fields: compid, compname
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
I hope this is what you asked for in the original post.
My Tables:
Tag (contains all tags), fields: tagid, tagname, tagdesc
Attributes (contains all attributes for all tags) fields: attrid, tagid (foreign key), attrname, attrdesc
Compatibility (contains all compatibility for all tags), fields: compid, tagid (foreign key), compname
for listing all attribues for a tag, make a simple select:
select * from attributes_tbl where tagid = '$tagid';
for listing compatible entries, make a simple select again:
select * from compability_tbl where tagid = '$tagid';
My Tables:
Tag (contains all tags), fields: tagid, tagname, tagdesc
Attributes (contains all attributes for all tags) fields: attrid, tagid (foreign key), attrname, attrdesc
Compatibility (contains all compatibility for all tags), fields: compid, tagid (foreign key), compname
for listing all attribues for a tag, make a simple select:
select * from attributes_tbl where tagid = '$tagid';
for listing compatible entries, make a simple select again:
select * from compability_tbl where tagid = '$tagid';
Well I'm not sure that would work because the Tag table would contain the tags (a, font, strong...) and the Attributes table would contain all attributes (style, href, class...).
Lets say the tag selected is "A" and id is 1. If i do your select it would select the attrid 1 from the attributes table but that would only get 1 attribute (attribute "style" for example). But I need all attributes for that tag. So I would need: href, class, style, id, ... to be selected from attributes table.
How would I know which attribute to select for each tag???
Lets say the tag selected is "A" and id is 1. If i do your select it would select the attrid 1 from the attributes table but that would only get 1 attribute (attribute "style" for example). But I need all attributes for that tag. So I would need: href, class, style, id, ... to be selected from attributes table.
How would I know which attribute to select for each tag???
Would I need another table to join tags and attributes?
sort of like this:
field 1 = tagid, field 2 = attrid
tagid=1, attrid=1
tagid=1, attrid=2
tagid=1 could be the "a" tag which has attributes: href, style...
attrid=1 could be "href". attrid=2 could be style. attrid=3 could be class.
Then I have tagid=2 which could be "p" tag which would be:
tagid=2, attrid=2
tagid=2, attrid=3
So basically I would create an additional table to contain all info. It seems like those ids repeats themselves a lot but would that be the best way to go?
sort of like this:
field 1 = tagid, field 2 = attrid
tagid=1, attrid=1
tagid=1, attrid=2
tagid=1 could be the "a" tag which has attributes: href, style...
attrid=1 could be "href". attrid=2 could be style. attrid=3 could be class.
Then I have tagid=2 which could be "p" tag which would be:
tagid=2, attrid=2
tagid=2, attrid=3
So basically I would create an additional table to contain all info. It seems like those ids repeats themselves a lot but would that be the best way to go?
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
Alright, it looks like you want something like this...
You have got the entire set of tags....tags_tbl
You have got the entire set of attributes available .....attributes_tbl
One tag can have many attributes similarly an attribute can be held by one or more tags...so there exists a many -to - many relationship.
Many to many relationship are solved by bringing in a new table which is basically the combination of primary keys of both tables, so it should be
TagsAttributesMap_tbl
tagid
attributeid
your query to retrieve all attributes for a tag should be...hopefully this works....give it a try...
You have got the entire set of tags....tags_tbl
You have got the entire set of attributes available .....attributes_tbl
One tag can have many attributes similarly an attribute can be held by one or more tags...so there exists a many -to - many relationship.
Many to many relationship are solved by bringing in a new table which is basically the combination of primary keys of both tables, so it should be
TagsAttributesMap_tbl
tagid
attributeid
your query to retrieve all attributes for a tag should be...hopefully this works....give it a try...
Code: Select all
select a.id, a.tagname, b.attrname, b.attrdesc
from Tags_tbl a
join TagsAttributesMap_tbl b on b.tagid = a.id
join Attributes_tbl c on c.id = b.tagid
where a.id = $tagid
order by c.attrname, c.attrdesc;