2017-02-15 81 views
-1

我试图在其他开关/外壳问题中找到我的答案。但我找不到解决方案。php开关/外壳不起作用

我有一个开关,将我的日期值分成4个不同的部分。 但是,当我想打印出来,它不起作用。我不知道我做错了什么。

这是一个错字还是?

在此先感谢。

我的代码

while (odbc_fetch_row($result)) { // while there are rows 
    $overweight = odbc_result($result, "Weight1") - 44000; 
    //$total_overweight += $overweight; 
    $date = date("Y-m-d", strtotime(odbc_result($result, "Date1"))); 
    $companies[] = odbc_result($result, "String3"); 
    $weight = odbc_result($result, "Weight1");          
    $item['nrplaat'] = odbc_result($result, "String1"); 
    $item['tptcode'] = odbc_result($result, "String3"); 
    $item['chrononr'] = odbc_result($result, "String15"); 
    $item['projectcode'] = odbc_result($result, "String4"); 
    $item['projectnaam'] = odbc_result($result, "String8"); 
    $item['1eweging'] = $weight; 
    $item['overweighted'] = $overweight; 
    $item['date'] = $date; 
    $item['2eweging'] = odbc_result($result, "Weight2"); 
    $item['netto'] = odbc_result($result, "Nett");                  
    switch($weight){ 
     case($weight > '44000' && $weight <= '44500'): 
      $item['class'] = 'lichtgroen'; 
     case($weight > '44500' && $weight <= '45000'): 
      $item['class'] = 'groen'; 
     case($weight > '45000' && $weight <= '46000'): 
      $item['class'] = 'donkergroen'; 
     case($weight > '46000' && $weight <= '47000'): 
      $item['class'] = 'bruingroen'; 
     case($weight > '47000' && $weight <= '48000'): 
      $item['class'] = 'lichtbruin'; 
     case($weight > '48000' && $weight <= '49000'): 
      $item['class'] = 'bruin'; 
     case($weight > '49000' && $weight <= '50000'): 
      $item['class'] = 'lichrood'; 
     case($weight > '50000'): 
      $item['class'] = 'rood';                    
    }          
    switch($date){ 
     case($date > $s_year.'-'.$quart1 && $date <= $s_year.'-'.$quart2): 
      $item['quarter'] = '1'; //kwartaal 1 
     case($date > $s_year.'-'.$quart2 && $date <= $s_year.'-'.$quart3): 
      $item['quarter'] = '2'; ////kwartaal 2 
     case($date > $s_year.'-'.$quart3 && $date <= $s_year.'-'.$quart4): 
      $item['quarter'] = '3'; ////kwartaal 3 
     case($date > $s_year.'-'.$quart4 && $date <= $s_year.'-'.$end): 
      $item['quarter'] = '4'; ////kwartaal 4           
    } 
    //$item['quarter'] = 1; WHEN I DO THIS, ALL RESULTS WILL PRINT OUT!!! 
    switch($item['quarter']){ 
     case '1': 
      print "<tr>\n"; 
      print " <td>" . $item['nrplaat'] . "\n"; 
      print " <td>" . $item['tptcode'] . "\n"; 
      print " <td>" . $item['chrononr'] . "\n"; 
      print " <td>" . $item['projectcode'] . "\n"; 
      print " <td>" . $item['projectnaam'] . "\n"; 
      print " <td>" . $item['1eweging'] . "\n"; 
      print " <td>" . "<span class=\"status\">".$item['class']."</span>" ."\n"; 
      print " <td>" . $item['overweighted'] . "\n"; 
      print " <td>" . $item['date'] . "\n"; 
      print " <td>" . $item['2eweging'] . "\n"; 
      print " <td>" . $item['netto'] . "\n"; 
      print "</tr>\n"; 
      break; 
    }          
} 
+0

你得到的错误是什么? – Jer

+0

没有错误。我很确定我的交换机有什么问题 –

回答

1

使用break;

case($date > $s_year.'-'.$quart1 && $date <= $s_year.'-'.$quart2): 
    $item['quarter'] = '1'; 
    break; 
1

你应该在每一种情况下的末尾添加break;声明。

1

也许是因为你没有在每个开关的情况下break;做。 尝试添加一些break;

请参阅here切换在PHP中。

0

你应该在'case'之后加'break'。如果你有一些'案件',这是非常重要的。请理解switch语句的概念,可以从http://php.net/manual/en/control-structures.switch.php中了解到。

如果你有一些'案件',你不使用'休息',这意味着下一个案件将继续进行。如果您在'大小写'之后使用'break',则切换过程将结束并且不会继续到下一个案例。也许你应该了解'继续':)