HTML Tags DB structure

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

HTML Tags DB structure

Post by vchris »

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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It looks like you have your three tables defined. Just as a key field in the Attributes and Compatibility tables to reference ID of the tag in the Tags table that they are associated with.
(#10850)
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

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
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

Is there anything I could read that would help me with this kind of DB?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the standards have all the information you should need to write this..
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

Thx feyd but do you have a link that could help me?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the standards are available from w3.org
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

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';
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

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???
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

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?
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

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...

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;
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

Thx raghavan20 I believe that's what I was looking for. I will create the DB and try your code. May take a couple days probly this weekend I'll do it.

Thanks again.
Post Reply