使用Codeigniter的多个IF,ELSEIF语句和&&运算符

问题描述 投票:0回答:3

我想创建一个更改行颜色的条件。但我的剧本并不适合我。以下是我的脚本:

if ($getType == 1){
   if (($intervalDay > '1') && ($intervalDay < '7')) {
      $strTblRes .= '<tr style="background-color:#43e537">';
      print_r('warna hijau');
   } elseif (($intervalDay > '7') && ($intervalDay < '14')) {
     $strTblRes .= '<tr style="background-color:#e5e234">';
     print_r('warna kuning');
   } elseif ($intervalDay > 14) {
     $strTblRes .= '<tr style="background-color:#e54242">';
   } 
} else {
  $strTblRes .= $tmplTbl['row_start']; 
}

请有人能告诉我哪里出错了。

php codeigniter if-statement
3个回答
0
投票

请更新代码,我刚刚输入默认值

$getType=1;

$intervalDay=8;

$strTblRes='';

if ($getType == 1){
   if (($intervalDay > '1') && ($intervalDay < '7')) {
      $strTblRes .= '<tr style="background-color:#43e537">';
      print_r('warna hijau');
   } elseif (($intervalDay > '7') && ($intervalDay < '14')) {
     $strTblRes .= '<tr style="background-color:#e5e234">';
     print_r('warna kuning');
   } elseif ($intervalDay > 14) {
     $strTblRes .= '<tr style="background-color:#e54242">';
   } 
} else {
  $strTblRes .= "<tr>"; 
}

0
投票

试试这段代码:

 $getType=1;

    $intervalDay=8;

    $strTblRes='';

    if ($getType == 1){
       if ($intervalDay > '1' && $intervalDay < '7') {
          $strTblRes .= '<tr style="background-color:#43e537">';
          print_r('warna hijau');
       } elseif ($intervalDay > '7' && $intervalDay < '14'){
         $strTblRes .= '<tr style="background-color:#e5e234">';
         print_r('warna kuning');
       } elseif ($intervalDay > 14) {
         $strTblRes .= '<tr style="background-color:#e54242">';
       } 
    } else {
      $strTblRes .= "<tr>"; 
    }

0
投票

试试这个

if ($getType == 1){

   if ( $intervalDay > 1  &&  $intervalDay < 7 ) {
      $strTblRes .= '<tr style="background-color:#43e537">';
      print_r('warna hijau');
   } 
   if ( $intervalDay > 7  && $intervalDay < 14 ) {
     $strTblRes .= '<tr style="background-color:#e5e234">';
     print_r('warna kuning');
   } 
   if ($intervalDay > 14) {
     $strTblRes .= '<tr style="background-color:#e54242">';
   } 


} 
else {
  $strTblRes .= $tmplTbl['row_start']; 
}
© www.soinside.com 2019 - 2024. All rights reserved.