homepage Welcome to WebmasterWorld Guest from 54.221.175.46
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
How to assign multiple parent id to articles
assigning two parent_id's
scraptoft




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

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?

 

jetboy




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

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.

scraptoft




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

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

LifeinAsia




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

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.

phranque




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved