我正在尝试使用if语句和两个.addClass背景颜色变量,基于'shift_times'的列值=“ SAT AM / SUN PM”或=“ SAT PM / SUN AM”。我正在寻找值是数字而不是文本的解决方案。

     $query = "SELECT COUNT(confirmed) as cnt,
     position, shift_times
     FROM volConfirm
     WHERE confirmed='yes'
     GROUP BY shift_times, position
     order by position";

     $result = mysql_query($query) or die(mysql_error());


     while($row = mysql_fetch_array($result))
      {
      echo "<tr>";
  echo "<td>" . $row['position'] ." ". $row['shift_times'] ."= " . $row['cnt'] . "</td>";
  echo "</tr>";
       }

最佳答案

您正在寻找这样的东西吗?

$query = "SELECT
      COUNT(confirmed) as cnt,
      position,
      shift_times
   FROM volConfirm
   WHERE confirmed='yes'
   GROUP BY shift_times, position
   ORDER BY position";

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)) {
   if ($row['shift_times'] === 'SAT AM/SUN PM') {
      echo '<tr class="class1">';
   } else if ($row['shift_times'] === 'SAT PM/SUN AM') {
      echo '<tr class="class2">';
   } else {
      echo '<tr>';
   }
   echo "<td>" . $row['position'] ." ". $row['shift_times'] ."= " . $row['cnt'] . "</td>";
   echo "</tr>";
}

关于php - .addClass与基于值的IF语句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10524751/

10-13 09:51