开发者

combining different resultsets in mysql (probably can't use union)

I'm building a tagging system for a website and I've come across a problem when displaying the items that have been tagged.

There are 3 different types of 开发者_JAVA技巧things one can tag on this website:

  1. Forum threads
  2. Reply posts to any of these threads
  3. Playlists created by users

So when browsing a certain tag, the user should be able to see all these different items. The problem here is of course that there are different table structures for all three items. And with threads, there are extra selects and joins to couple of other tables. so obviously the data selected won't match across tables and that probably leaves out MySQL's UNION syntax (or so I think).

What are my options?

Table schema:

threads: threadid, title, thread_type (article, event, artist, thread)
events: eventid (corresponds to threadid on join), title, begin_time, end_time
artists: artistid (corresponds to threadid on join), artist_username
news: newsid, news_title, is_thread, threadid, postid (joined on either one; for threads, is_thread is used also)
thread replies: postid, threadid, thread_title
playlists: playlistid, playlist_title (is never associated with any previously mentioned tables)


I've got an idea I'm gonna try out. Since each connnection is a table row in tags_connections table, I'm gonna make some JOINs and let PHP decide later on what to display. I'll report back on my success or lack thereof

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜