php - How to add manually related posts to a post? -


i designing blog site in php users can add manually related posts post.

i thought use autoincrement integer posts related.

this table:

blog: -id -related ( it's 0 if there aren't related posts or contain autoincremet integer same posts related ) -id_user -title -body -date 

i prefer not use "related table" if possible avoid complex queries.

so need way auto increment integer in case or can suggest me other solutions :)

why not have second table? it's robust solution, , doesn't complify queries @ all.

you should have second table, related-posts, 2 fields: original , related.

neither unique, following possible (assuming 1,2,3,4 post ids)

o | r --+-- 1 | 2 1 | 3 2 | 3 2 | 4 4 | 1 

when need find posts related post 1 (for example), query

select `related` `related-posts` `original` = 1; 

this give related post ids.


this kind of relationship called many-to-many relationship, 1 post can have many related posts, , 1 post can related many original posts.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -