Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP,Bootstrap-根据数字范围更改跨度标签_Php_Twitter Bootstrap - Fatal编程技术网

PHP,Bootstrap-根据数字范围更改跨度标签

PHP,Bootstrap-根据数字范围更改跨度标签,php,twitter-bootstrap,Php,Twitter Bootstrap,我正在显示数据库中的统计数据,如果数字在80和99之间,我希望标签成功,如果数字在51和79之间,标签警告,如果数字在0和50之间,标签危险 大概是这样的: $query = $db->query("SELECT * FROM stats"); foreach ($query as $row) { $points = $row['points']; $votes = $row['votes']; $postcla

我正在显示数据库中的统计数据,如果数字在80和99之间,我希望标签成功,如果数字在51和79之间,标签警告,如果数字在0和50之间,标签危险

大概是这样的:

    $query = $db->query("SELECT * FROM stats");
    foreach ($query as $row) {

                $points = $row['points'];
            $votes = $row['votes'];


$postclass = "";

foreach (range(0,50) as $row) {
    $posclass = "danger";
}

foreach (range(51,79) as $row) {
    $posclass = "warning";
}

foreach (range(80,99) as $row) {
    $posclass = "success";
}


echo '
<span class="label label-'.$posclass.'" >'.$points.'</span>
<span class="label label-'.$posclass.'" >'.$votes.'</span>
';

}
$query=$db->query(“从统计数据中选择*);
foreach($queryas$row){
$points=$row['points'];
$voces=$row['voces'];
$postclass=“”;
foreach(范围(0,50)为$row){
$posclass=“危险”;
}
foreach(范围(51,79)为美元行){
$posclass=“警告”;
}
foreach(范围(80,99)为$row){
$posclass=“成功”;
}
回声'
“.$points。”
“.$票。”
';
}

谢谢

这很奇怪,你在一系列数字上循环,并将数字分配给$row。。。如果我理解您的愿望,我认为您需要更改代码,使其看起来像这样,特别是在每一行上,以查看$points值是否在特定范围内

上次更新为积分和投票添加了一个单独的标签

$postclass = "";
if ($points > 0 && $points <= 50) {
    $pointsLabel = "danger";
} else if ($points > 50 && $points <= 79) {
    $pointsLabel = "warning";
} else {
    $pointsLabel = "success";
}

if ($votes > 0 && $votes<= 50) {
    $votesLabel = "danger";
} else if ($votes> 50 && $votes<= 79) {
    $votesLabel = "warning";
} else {
    $votesLabel = "success";
}

echo '
<span class="label label-'.$pointsLabel.'" >'.$points.'</span>
<span class="label label-'.$votesLabel.'" >'.$votes.'</span>
';
$postclass=”“;

如果($points>0&&$points 50&&&$points 0&&&$vots 50&&$votest这不起作用,我会问你怎么做。你想比较什么数字?$row是一个数组。id?行总数?问题是每个(范围(0,50)作为$row的奇数行,但你的问题中没有问题。我假设你想要($points>=0&&$points如果$voces或$points在其中一个范围内,请相应地更改标签。您刚才发布的代码有很多错误。注释说,“如果$voces或$points在其中一个范围内”,因此您也应该添加$voces的检查。此外,我将默认为“危险”,而不是“成功”以防万一。这是我想要的,但是有多个变量,比如$points和$voces,我没有显示,我是说多个,我是说20-30个变量,我应该这样做吗?@user1626410是的,但我刚刚编辑了它,以便对点和投票使用标签