使用 PHP 使用 MYSQL 数据引导进度条? [英] Bootstrap progress bar with MYSQL data using PHP?
问题描述
我在 MYSQL 数据库中有一个表,有 14586 条记录.
每条记录都有一个名为 active
的行,值为 0.
在某些时候,这个 active
行的值变为 1.
我需要做的是简单地显示一个 bootstrap 进度条
,显示进度条中具有 active=1
的字段.
我尝试过这样的事情:
PHP:
$result = mysqli_query($db_conx, "SELECT count(*) FROM mytable WHERE active=1");$row = mysqli_fetch_row($result);$num = $row[0];
引导 HTML:
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $num; ?>%"><?php echo $num;?>%
但这是错误的,因为我在进度条中得到了一个像 14586% 这样的愚蠢数字.
有人可以就此提出建议吗?
任何帮助都会很棒.
提前致谢.
您需要获取没有 WHERE
过滤器的总记录数和带有 WHERE active=1
过滤器的总记录数代码>.这将允许您计算从 0 到 100 的百分比值.
[活动总数=1]/[总记录数] * 100 = [0 - 100 的百分比]
示例:7293/14586 = 0.5 * 100 = 50%
参见:https://en.wikipedia.org/wiki/Percentage>
I have a table in MYSQL database with 14586 records.
each record has a row called active
with a value of 0.
at some point the value of this active
row becomes 1.
what i need to do is to simply display a bootstrap progress bar
showing the fields that have the active=1
in the progress bar.
I tried something like this:
PHP:
$result = mysqli_query($db_conx, "SELECT count(*) FROM mytable WHERE active=1");
$row = mysqli_fetch_row($result);
$num = $row[0];
Bootstrap HTML:
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $num; ?>%">
<?php echo $num; ?>%
</div>
</div>
But this is wrong because I get a silly number like this 14586% in the progress bar.
Could someone please advice on this?
any help would be great.
Thanks in advance.
You need to get the total records with no WHERE
filter AND the total records with the WHERE active=1
. This will allow you to calculate a percent value from 0 to 100.
[total active=1] / [total records] * 100 = [percent from 0 - 100]
Example: 7293 / 14586 = 0.5 * 100 = 50%
See: https://en.wikipedia.org/wiki/Percentage
这篇关于使用 PHP 使用 MYSQL 数据引导进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!