drxm5014 2014-05-08 20:26
浏览 359
已采纳

页面视图在Mysql中计数。 更好的方法吗?

The idea is to show how many times people have visited a certain product page.

So far I've come up with two options.

  1. Add a new column called "views" in the products table(Mysql). This seems to be the most simple and fastest way to setup.

  2. Create a new table called "product_views". Have 3 columns for it. id, product id, views. From there you can use JOINS to update and call for view count.

So what I would like to know which option is better?

  • 写回答

2条回答 默认 最新

  • doucang5542 2014-05-08 20:33
    关注

    Depends on what you want to go for. I usually log page views on a table such as:

    ID (int), PRODUCT_ID (int), IP_ADDRESS (varchar(15)), VIEW_TIME (datetime)
    

    and that gives me the ability to count either full views or unique views by IP ADDRESS and just do a COUNT(*) on the table, and an added benefit of having a log of who visits the page. Obviously this will increase your space requirement needed for the DB.

    If you're going to just create a product view column, then create a stored procedure that will take in the product id as a parameter and increase the value of the product_view column by 1 each time it's run.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器