Jump to content

Content popularity


Morthian

Recommended Posts

By the way, just if I wasn't clear, when I say content I mean records in a database. For example, Newgrounds shows its most popular flash submissions on its Portal page. DeviantArt does the same sort of thing with art submissions. I think somehow sorting records by the most views in the last week might be a good way of showing the "most popular" items. But like I said, I would have no clue how to actually do this.

Link to comment
Share on other sites

Well content im taking it means news.  In the news table you need to make a column  called views.  Then when someone clicks the link to view the news u need to have a script at the top of that page to update the views for that news.  So day you had a link like www.mysite.com/viewnews.php?id=4 then at the top of the page

you would do

<?php
$get_news_views = mysql_query("SELECT * FROM `table_name` WHERE news_id = '".$_GET['id']."'") or die(mysql_error());
$news_views = mysql_fetch_array($get_news_views);
$views = $news_views['views'] + 1;
mysql_query("UPDATE `table_name` SET views = '".$views."' WHERE news_id = '".$_GET['id']."'") or die(mysql_error());
?>

Link to comment
Share on other sites

Yes, I know how to record a total number of views. I am asking how to record the number of views in a given time, such as a day or a week. On GameSpot, the popularity of the games is based on total unique views from yesterday. Since my site is certainly not as well known as GameSpot, I figure it would be better to base the popularity of content on views from the last week, or last 7 days. How can I do this?

Link to comment
Share on other sites

You could make a new table in your DB called "views", have track the following fields:

 

content_id (int) (unique)

views (int)

date (date)

 

When the page is accessed, check if a DB row already exists for that content that day and update it. Otherwise create a new row.

 

SELECT COUNT(*) FROM views WHERE content_id = $content_id and date = NOW()

 

Then when you want to run a query for the most popular items in a specific time frame, simply run a query that looks for the highest views later than a certain date, and limit the results to however many items you want to show.

 

SELECT * FROM views WHERE date > $limit_date ORDER BY views DESC LIMIT 5

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.