如何制作一个php文章计数器?

发布于 2024-11-06 21:34:13 字数 391 浏览 0 评论 0原文

我写了一些简单的文章脚本。现在我想添加一些文章计数器。

如果有3种可能性就应该做一个文章计数器。

  1. 该文章已被打开阅读。(每页仅一篇整篇文章,计1次)
  2. 该文章已在内容搜索列表中被搜索到(标题和简短内容描述每页5条,计1次)。那么如果打开阅读整篇文章内容,则会再算1次。)
  3. 该文章已通过随机方式显示在首页中(带有标题和简短描述,将算1次)

有什么好的建议如何做到这些更好的?

哪种数据库设计更好?将文章和计数放在一张表中?或者制作两张桌子?

谁能给我推荐一些php文章计数器脚本,如果主要规则写入像class.php这样的文件,然后包含到我的每个页面中。

谢谢。

I write some simple article scripts. Now I want add some article counter.

If there have 3 possibility it should make an article counter.

  1. the article has been opened for read.(only one whole article per page, it will count 1 time)
  2. the article has been searched in a content search list(with title and short content description 5 items per page, it will count 1 time. then if open to read whole article content, it will count another 1 time.)
  3. the article has been showed in the home page by Random (with title and short description, it will count 1 time)

Is there any good suggestion how to do these better?

Which database design is better? put article and count number in one table? or make two tables?

Can anyone recommend me some php article counter script, if the main rules write into a file like class.php then include into my every page.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉殇 2024-11-13 21:34:13

如果您要计算一篇文章的点击次数,请创建一个列,并在每次有人访问该页面时向其中添加一个列。

类似于:

$sql = "UPDATE table SET count=count+1 WHERE id='$id'";
mysql_query($sql);

将表 table 中的列 count 加 1。然后您就可以检索该值。

If you are counting the number of hits on an article, create a column and add one to it every time somebody accesses the page.

Something like:

$sql = "UPDATE table SET count=count+1 WHERE id='$id'";
mysql_query($sql);

Would increment the column count in the table table by 1. Then you could just retrieve that value.

苹果你个爱泡泡 2024-11-13 21:34:13

您可以做的是使用自动递增的数据库,并在查看页面时仅递增该值,并根据需要显示该值。

以下是如何设置自动增量

然后更新“值”(你不必实际更新它会AI的任何内容)

mysql_query("UPDATE COUNTER SET HITS = ''");

然后只显示视图

$result = mysql_query("SELECT * FROM PAGEVIEWS");

while($row = mysql_fetch_array($result))
  {
  echo $row['COUNTER'];
  }

这超出了我的想象 - 它应该可以工作。

What you could do is use the database that auto increments and just increment that value when the page is viewed, and display that value if you want.

Here is how you can setup the auto increment.

Then update the "value" (you don't have to actually update anything it will AI)

mysql_query("UPDATE COUNTER SET HITS = ''");

Then just display the view

$result = mysql_query("SELECT * FROM PAGEVIEWS");

while($row = mysql_fetch_array($result))
  {
  echo $row['COUNTER'];
  }

This is off the top of my head - it should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文