Most Popular / Related Articles

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
greenyeyes26
Forum Newbie
Posts: 4
Joined: Wed Aug 08, 2007 2:14 pm

Most Popular / Related Articles

Post by greenyeyes26 »

Hi there

i have a problem building a site with news

table news
news_id, news_title, news_date, news_category

now, i want to present the 5 most popular articles based on clicks (views) of every article in a place of the main page.

The page that displays the articles is e.g. article.php?news_id=453

Also, i need to find a solution to present the 5 most related articles to the one is viewed.

Please ... urgent need for help ...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. Your query would sort based on view count
  2. Your query would use keyword linking. It can be fairly complicated.
In either respect, this has almost nothing to do with PHP specifically.
greenyeyes26
Forum Newbie
Posts: 4
Joined: Wed Aug 08, 2007 2:14 pm

More specifically

Post by greenyeyes26 »

Thanks for help ..

I'm just trying to find how i will implement this view count for the last 7 days ... (for the most popular)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You'll need to log date and time requests for each page. Depending on how you want to do it, a query could either update an aggregate count column in another table with the current information, or the query to aggregate the information could be done live. Personally, I would go with the former over the latter.
greenyeyes26
Forum Newbie
Posts: 4
Joined: Wed Aug 08, 2007 2:14 pm

Trying to get out of chaos ...

Post by greenyeyes26 »

Thanks friend ... I just don't know the code to log the date and time of the articles. I could go for the first solution also .. if i knew the way

Thanks again...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There are several ways to get the current date and time information. One being date() and another being from the database you are using. There isn't a wrong choice here, only preference. If you're hoping for me to post some code, you'll be disappointed.
greenyeyes26
Forum Newbie
Posts: 4
Joined: Wed Aug 08, 2007 2:14 pm

Thanks

Post by greenyeyes26 »

thanks anyway friend
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Hehe.

You could just use the separate table that logs the date and article / page, and then just increment the view count for each day. You could also use that to delete outdated information as well.

A good table structure would be a page / article id, a date, and a view count. Simple.
Post Reply