【发布时间】:2017-04-06 21:52:32
【问题描述】:
我创建了一个基于帖子的级别系统。
Level 1 = 1-25 posts
Level 2 = 26-50 posts
Level 3 = 51-250 posts, etc...
我还想显示一个进度条
通常你会这样:
$author_posts = 15;
$progress = ($author_posts * 100) / 25; //(level 1)
那么进度百分比就是60%。
但是如果用户已经到达level 3,我应该使用什么?
if( $author_posts >= '250' ) {
$progress = '100';
} elseif( $author_posts < '51' ) {
$progress = '0';
} else {
$progress = // what should I use here?
}
<div class="progress-bar" style="width:<?php echo esc_attr( $progress ); ?>%;"></div>
【问题讨论】:
-
你能解释一下你所说的百分比是什么意思吗?到下一个级别是百分比吗?
-
基础数学 = ($author_posts / 250) *100
-
当前关卡(level3)内的百分比。或者在第 3 级被清除之前完成了多少百分比。我认为应该是这样的,但我不确定:
$progress ( $author_posts * 100 ) / ( 250 - 51 );
标签: php progress-bar percentage