每次在浏览器中加载数据库中的页面时,Mysql 数据类型或 php 代码都会增加 1
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
老实说,我们需要看看你的 PHP 和 MySQL 是如何布局的。您想要有人为您编写还是您想学习?
查询将是这样的:
我相信这会起作用。
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:
I believe that would work.
id
is your lyric id andcount
is your column for keeping track of numbers.并在每次加载歌词页面时执行该操作。
and have that execute every time the lyrics page is loaded.
我从来都不是“视图”列的粉丝,因为没有证据证明这是实际的数字,相反,我会创建一个事务表,在其中存储时间戳和其他一些信息,然后如果我想获得计算歌词被查看的次数我会这样做:
出于演示目的,表格设计可能如下所示:
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:
For demonstration purposes, the table design might look like: