If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to show related articles ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-20-10, 11:57
linux1880 linux1880 is offline
Registered User
 
Join Date: Jul 2010
Posts: 39
How to show related articles ?

Hello friends,

I am building news site in php mysql, I want to show related articles on that article, how do i achieve it please show me sql example. Thanks
Reply With Quote
  #2 (permalink)  
Old 12-20-10, 12:13
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
how do you know what article is related to another?
whatever mechanism you use place that in the where clause

eg
select my, comma, separated, column, list from my table
where articlerealtion = blah



or where articlerelation in (a, list, of, articles)
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 12-20-10, 12:19
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by linux1880 View Post
please show me sql example.
Code:
CREATE TABLE articles
( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT
, title VARCHAR(99) NOT NULL
, dateposted DATE NOT NULL
, author VARCHAR(99) NOT NULL
);
CREATE TABLE article_rel
( this_article INTEGER NOT NULL REFERENCES articles (id)
, related_article INTEGER NOT NULL REFERENCES articles (id) 
, PRIMARY KEY (this_article,related_article)
);

SELECT related.id
     , related.title
     , related.dateposted
     , related.author
  FROM article_rel
INNER
  JOIN articles AS related
    ON related.id = article_rel.related_article
 WHERE article_rel.this_article = 937
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 12-20-10, 19:27
linux1880 linux1880 is offline
Registered User
 
Join Date: Jul 2010
Posts: 39
How to write a most popular articles by views

Hello friends agaain,

I am trying to write a php program for my news site where we can display "most popular articles by views" please give me an idea what database table structure I should make. Thanks
Reply With Quote
  #5 (permalink)  
Old 12-20-10, 22:24
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by linux1880 View Post
please give me an idea what database table structure I should make.
Code:
CREATE TABLE articles
( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT
, title VARCHAR(99) NOT NULL
, dateposted DATE NOT NULL
, author VARCHAR(99) NOT NULL
, views INTEGER NOT NULL DEFAULT 0
);
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 12-21-10, 15:21
linux1880 linux1880 is offline
Registered User
 
Join Date: Jul 2010
Posts: 39
Thanks r937

I am bit confused about the related article article_rel table do i need to send id's in article_rel table with php or we should write database function for that ? Your suggestion will be appreceated. Thanks
Reply With Quote
  #7 (permalink)  
Old 12-21-10, 15:25
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by linux1880 View Post
do i need to send id's in article_rel table with php
yes, sending with php will be okay
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 12-21-10, 20:54
linux1880 linux1880 is offline
Registered User
 
Join Date: Jul 2010
Posts: 39
Thank you,

just wondering how do i do it to show popular post this week , this month and this year.
Reply With Quote
  #9 (permalink)  
Old 12-22-10, 00:23
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
related articles... check

most popular by views... check

popular this week, this month, this year... time for you to try it yourself
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Tags
related articles

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On