3 回答

TA貢獻(xiàn)1886條經(jīng)驗(yàn) 獲得超2個贊
只需將大于改為小于即可。
<?php
if($outoff!=0)
{
$grade = ($score/$outoff)*100;
if($grade <= 39)
{
echo '<span class="text-danger">Bad</span>';
}
else if($grade <=74) //Change to less than here.
{
echo '<span class="text-warning">Average</span>';
}
else if($grade <=100) //Change to less than here.
{
echo '<span class="text-success">Good</span>';
}
}
else
{
//no comment please
}

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超11個贊
您需要修改條件,以便不會錯過分?jǐn)?shù)。
if因此,請使用and `else if'定義 3 個分?jǐn)?shù)范圍。
Range 1: 0-39: if ($grade <= 39) {
Range 2: 40-74: else if($grade <=74) {
Range 3: 75-100: else if($grade <=100) {
這樣,首先if檢查成績是否小于或等于39。
如果是,則等級為Bad。
否則,如果score,不適合此范圍,它將在下一個范圍內(nèi)繼續(xù)if else:如果不適合,則40-74方法相同。75-100
更正的代碼:
if ($outoff!=0) {
$grade = ($score/$outoff)*100;
if ($grade <= 39) { // Score range: 0-39
echo '<span class="text-danger">Bad</span>';
}
// If $score is coming to this else if means it is definitely
// greater than 39: that is 40+
// Score range: 40-74 as it is in else if after if of `39`
else if($grade <=74) {
echo '<span class="text-warning">Average</span>';
}
// Score range: 75-100 as it is in else if after 0 - 39 and 40 - 74
else if($grade <=100) {
echo '<span class="text-success">Good</span>';
}
}

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個贊
您必須對代碼進(jìn)行如下更改:
<?php
if($outoff!=0)
{
$grade = ($score/$outoff)*100;
if( $grade >= 0 && $grade < 40 ) {
echo '<span class="text-danger">Bad</span>';
}
else if( $grade > 39 && $grade < 75 ) {
echo '<span class="text-warning">Average</span>';
}
else if($grade > 74 && $grade <= 100 ) {
echo '<span class="text-success">Good</span>';
}
}
else
{
//no comment please
}
?>
- 3 回答
- 0 關(guān)注
- 167 瀏覽
添加回答
舉報(bào)