Welcome Guest, Not a member yet? Register   Sign In
What's wrong with this code? =/
#10

[eluser]emily12[/eluser]
Well, that IS very easy and I've done that for just about every query relating to comments articles so far, but the problem is that we're looking at more than one table and each table has unique columns but they need to be treated the same.
Quote:ENTarticleid (from entertainment)
NEWSarticleid (from news)
NORMarticleid (from articles) //misc stuff

To name a few. Then we join...
Quote:entertainment_articles(entarticleid) with entertainment_comments(ent_articles_article) // joining id's

news_articles(narticleid) with news_comments(news_articles_article) // joining id's

articles(articleid) with articles_comments(articles_article) // joining id, see NORMarticleid further up

Okay so now we theoretically connected the comments from different sections(tables) to their own respective article. Now let's make sure they know their category so a url can be generated


Quote:entertainment_articles(type) -> entertainment_categories // category id
news_articles(subcat) -> news_categories // category id
articles(subcat) -> articles_categories // category id

Now comments should know what article they are from, and what category they're in, thanks to the article saying the (subcat) is x(int) in their given category. We can use a simple conditional to find out what category they're from to form a url.

The next step is to assign users to these comments, so we use the user's table and the comments table from each section.

Quote:entertainment_comments(author_id) -> users(id) // cross checks the comment's author id with users's id.
news_comments(author_id) -> users(id) // same thing
articles(author_id) -> users(id) // again

Okay so now our results should look like assuming the view file was created (if limited to two results):
Quote:Myusername
Hello world, this is a test post.
06 - 06 - 2012, 2:45 PM
urlgoeshere/

Myusername
Hello world, this is the second post
06 - 06 - 2012, 2:48 PM
urlgoeshere/

The last thing on this list is to determine how to order it by, and each comment has their own prefix like said in the beggining of this post (ENTarticleid, NEWSarticleid etc...).

The date would be similar:
Quote:entertainment_comments(cme_date_posted)
news_comments(ncm_date_posted)
article_comments(cm_date_posted)

Ridiculous isn't it? I figured that this problem would be an amazing learning experience but it's way over my head with the usage of mysql lol X.x I heard create view might be necessary, also join, union and alias might be used too. This should be an exam question to be honest lol!


Messages In This Thread
What's wrong with this code? =/ - by El Forum - 06-06-2012, 12:25 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 12:44 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 01:26 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 01:32 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 01:34 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 01:44 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 01:46 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 01:51 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 02:08 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 02:50 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 04:16 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 04:22 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 05:02 PM
What's wrong with this code? =/ - by El Forum - 06-06-2012, 05:45 PM



Theme © iAndrew 2016 - Forum software by © MyBB