Jump to content

mysql organization help


randomfool

Recommended Posts

I'm working on a website and trying to figure out a way to organize my db and dbs are my specialty. What I'm tryng to figure out is how I can tag posts with categories and then find those posts later usnig the categories. Right now I have three tables. As of right now none of this is coded it's all on paper but eventually it'll be done using mysql 4.1.

 

Posts
title pid content
Test post 01 lorem ipsum....

Categories
name tid
cat1 01
cat2 02

linkp2c
pid tid
01 01
01 02

I'm trying to figure out how I can use the categories to pick a post for example I want to find test post using category 01 and 02. Does this make any sense? Thanks!

 

-Ryan

Link to comment
Share on other sites

SELECT DISTINCT title,content FROM posts,categories,linkp2c WHERE linkp2c.tid=categories.tid AND posts.pid=linkp2c.pid AND (categories.name='cat1' OR categories.name='cat2');

 

or maybe

 

SELECT DISTINCT title,content
FROM
categories JOIN linkp2c ON categories.tid=linkp2c.tid
JOIN posts ON posts.pid=linkp2c.pid
WHERE
categories.name='cat1'
OR categories.name='cat2'

 

Link to comment
Share on other sites

Thanks for the replies.

 

This is my first project that requires a lot of database access involved. I want to make sure that what I'm doing makes sense before I write a lot of code and find out I'm doing something stupid. In practice I won't know the categories until someone picks them. The idea is to allow people to filter posts by multiple categories so they can select cat1, cat2, or cat 1 & 2 and only see posts that match all of the selected categories.

 

-Ryan

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.