Answer the question
In order to leave comments, you need to log in
How to fix a bug in the code?
Can you please tell me how to fix the code? My $ost variable displays how many days are left until the announcement expires, but it does not work correctly.
The idea is 30 days green, 20 days orange, 10 red.
The code itself is:
?>
<div class='progressBlock'>
<div class='percent'></div>
</div>
<style>
.progressBlock {
width: 100px;
height: 10px;
border-radius: 3px;
border: 1px solid black;
position: relative;
}
.percent{
position: absolute;
<?
//$ost = 30; //Осталось 10 дней это для примера так работает
$total = 30; //Всего 30 дней
$p = $ost * 100 / $total; // Получим 33%
echo "width: $p%;\n";
$color = "lime";
if ($ost >= 10 and $ost < 20) $color = "yellow";
if ($ost < 10) $color = "red";
echo "background-color: $color;";
?>
height: 10px;
}
</style>
<?
Answer the question
In order to leave comments, you need to log in
switch (true){
case $ost>=10 && $ost <20:
$color = "yellow";
break;
case $ost<10:
$color = "red";
break;
default:
$color = 'green';
break;
}
Good afternoon.
I'll put in my five cents :)
$ost = 9;
switch (true){
case $ost >= 10 && $ost < 20:
$color = "yellow";
break;
case $ost < 10:
$color = "red";
break;
case $ost > 20:
$color = 'green';
break;
}
?>
<div style="color:<?= $color ?>">test</div>
$ost = 45;
$p = $ost * 100 / $total;
// далее остальной код
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question