每次在浏览器中加载数据库中的页面时,Mysql 数据类型或 php 代码都会增加 1

发布于 2024-12-13 21:14:48 字数 227 浏览 4 评论 0原文

我正在尝试使用 Dreamweaver 构建一个歌词数据库网站。 我有一个歌词表,还有一个名为“视图”的列,每次在浏览器中查看特定歌词时,我希望该列增加 1。

我如何使用 mysql 来完成这个任务? 我可以使用什么 mysql 数据类型或 PHP?

请彻底解释一下,因为我不太了解 php 或 mysql,我只是在尝试。

请记住我正在使用 Dreamweaver。

谢谢。

I am trying to use Dreamweaver to build a Lyrics database website.
I have a table for the lyrics and I have a column called "views" that I want to increase by 1 every time that particular lyric is viewed in a browser.

How can I accomplish this using mysql?
What mysql datatype Or PHP can I use?

Please explain thoroughly because I do not know php or mysql that well, I'm just trying.

Remember I am using Dreamweaver.

Thanks.

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

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

发布评论

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

评论(3

别把无礼当个性 2024-12-20 21:14:48

老实说,我们需要看看你的 PHP 和 MySQL 是如何布局的。您想要有人为您编写还是您想学习?

查询将是这样的:

$query = "UPDATE `myviewstable` SET count = count+1 WHERE id = '$id'";

我相信这会起作用。 id 是您的歌词 ID,count 是您用于跟踪数字的列。

Well we would need to see how your PHP and MySQL is laid out to be honest. Do you want someone to just write it for you or do you want to learn?

The query would be something like this:

$query = "UPDATE `myviewstable` SET count = count+1 WHERE id = '$id'";

I believe that would work. id is your lyric id and count is your column for keeping track of numbers.

菩提树下叶撕阳。 2024-12-20 21:14:48
UPDATE lyrics SET views=views+1 WHERE id = $id_of_song

并在每次加载歌词页面时执行该操作。

UPDATE lyrics SET views=views+1 WHERE id = $id_of_song

and have that execute every time the lyrics page is loaded.

一身骄傲 2024-12-20 21:14:48

我从来都不是“视图”列的粉丝,因为没有证据证明这是实际的数字,相反,我会创建一个事务表,在其中存储时间戳和其他一些信息,然后如果我想获得计算歌词被查看的次数我会这样做:

SELECT count(*) FROM lyric_views WHERE lyric_id = ?

出于演示目的,表格设计可能如下所示:

CREATE TABLE `lyric_views` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `lyric_id` int(11) unsigned NOT NULL,
  `viewed_at` timestamp NOT NULL default CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8

I've never been a fan of a 'views' column because there is no proof that is the actual number, instead I would create a transaction table where I would store a timestamp along with some other info, then if I wanted to get a count of how many times the lyrics were viewed I would just do:

SELECT count(*) FROM lyric_views WHERE lyric_id = ?

For demonstration purposes, the table design might look like:

CREATE TABLE `lyric_views` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `lyric_id` int(11) unsigned NOT NULL,
  `viewed_at` timestamp NOT NULL default CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文