Injecting tags into database with php and mySQL

Hi,

I have looked around online but all of them are about making tag clouds which is not what I am after…

I have 3 tables,

  • pages (with page id, etc)
  • tags (tag id, and tag name)
  • tagged (tagged id, tag id, and page id)

the idea of having tags and tagged is that tags table only receive unique tag names which means the same tag name cannot be repeated twice in this table. while in tagged table can receive duplicated page ids and tag ids. does it make sense…?

it will be great if you can give me a hint how to inject tags into these tables or any online tutorials that I can pick up.

many thanks,
Lau

tagged id field is needless, and all other structure is all right
what troubles you?
once page is entered, get tag ids and insert it into tagged table along with page id
one tag per row

hi, thanks for the reply.

the trouble is, for instance i am going to insert two different pages with the same tag name, this tag name should not be inserted into tags table if this tag name has already existed but into tagged table with page id and retrieving the tag id from tags table.

thanks.

I believe that if you set both the tag id and page id as primary keys, that the database will prevent you from adding entries where both are already duplicates.

The MySQL Forum is likely to have much greater detail about such techniques.