Welcome to WebmasterWorld Guest from 54.163.84.199

Forum Moderators: open

How to assign multiple parent id to articles

assigning two parent_id's

   
11:46 am on Aug 4, 2008 (gmt 0)

5+ Year Member



I am using a simple parent_id structure to find content articles from mysql.

I am trying to figure a way to assign multiple parent_id's to content aritcles, So both query a) and b) will return content record ID 1.

CONTENT
------------
ID ¦ 1
Parent_ID¦ 8,9
------------

a)
SELECT * FROM content where parent_id = 8

b)
SELECT * FROM content where parent_id = 9

Is this possible?

1:27 pm on Aug 4, 2008 (gmt 0)

10+ Year Member



Assuming that each parent (I'm assuming categories) can have multiple children (articles), then you're talking about a many-to-many relationship.

You'll need to introduce a new table to manage that relationship, which will only contain references to the IDs of your categories and articles.

category
------------
category_id
category_name
------------

content
------------
content_id
content_title
content_body
------------

category_content_relationship
------------
category_id
content_id
------------

Now, any category can have a relationship with any content.

2:10 pm on Aug 4, 2008 (gmt 0)

5+ Year Member



I am struggling to get my head around how you would implement the category_content_relationship. Could you give me a demo query?

Thanks Jetboy

3:35 pm on Aug 4, 2008 (gmt 0)

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



SELECT category_ID
WHERE content_id=ThisCountentID

This will return all the "Parent IDs" for the article with content_id of ThesContentID, which is the result you are looking for.

7:01 am on Aug 5, 2008 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



i think you want something like this:
CONTENT
------------
ID
...

PARENT_CONTENT
------------
PARENT_ID
CONTENT_ID

select CONTENT.* from PARENT_CONTENT,CONTENT where PARENT_CONTENT.CONTENT_ID=CONTENT.ID and PARENT_ID=8

 

Featured Threads

Hot Threads This Week

Hot Threads This Month