【问题标题】:Generating a sum of up / down ratings up to 100%产生高达 100% 的向上/向下评级的总和
【发布时间】:2018-09-08 09:52:49
【问题描述】:

我写了一个评分系统(上/下)。用户将投票保存在数据库中:

articles (
   id int not null auto_increment,
   article_title varchar (100) not null,
   ...
   vote_up int not null default '0',
   vote_down int not null default '0',
   vote_sum int not null default '0'
   ..
)

我想显示一个显示向上/向下评级状态的栏:

如何提高/降低成绩的百分比?你有什么想法吗?

【问题讨论】:

  • 你有什么尝试吗?
  • 我猜做一个简单的vote_up / vote_sum 不是这里的问题。然后怎样呢?尽量做到具体
  • 你想要这样吗:3v4l.org/8jagK

标签: php


【解决方案1】:

您可以通过创建 2-spans(或 div)并相应地更改它们的百分比宽度来做到这一点。

例如。如果 vote_up = 20 & vote_down = 30 那么

    total_votes = vote_up + vote_down;

    vote_up_pctg = vote_up/total_votes *100;
    vote_down_pctg = vote_down/total_votes *100;

所以第一个跨度或 div 宽度将为 40%,第二个为 60%。

您必须使用 CSS 和 PHP(或任何服务器端语言)完成以上所有操作。你也可以在 js 中执行此操作,但加载后需要一些时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 2012-02-16
    • 2011-02-03
    • 1970-01-01
    • 2020-09-16
    • 2015-10-14
    相关资源
    最近更新 更多