| |
|
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.
|
 |

12-20-10, 11:57
|
|
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
|
|

12-20-10, 12:13
|
|
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
|
|

12-20-10, 12:19
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
|
|
|
|
Quote:
Originally Posted by linux1880
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
|
|

12-20-10, 19:27
|
|
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
|
|

12-20-10, 22:24
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
|
|
Quote:
Originally Posted by linux1880
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
);
|
|

12-21-10, 15:21
|
|
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
|
|

12-21-10, 15:25
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
|
|
Quote:
Originally Posted by linux1880
do i need to send id's in article_rel table with php
|
yes, sending with php will be okay 
|
|

12-21-10, 20:54
|
|
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.
|
|

12-22-10, 00:23
|
|
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
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|