根据SQL查询结果更改表中的输出

时间:2013-08-04 00:44:45

标签: php sql-server

我试图根据sql查询中的列是0还是1来改变表中两列的打印结果

我做了一个$ Status的回显,它输出了一个正确的值列表,但它高于我的表。我是否错误地将其放入表格行?

我的其余数据正确地填充了表,它只是那两列。我目前已将该部分注释掉,因此表中的输出分别为0或1。我还有一个特定的列旁边,一个注释掉的变量,如果它们要正确输出它们将会是什么。

非常感谢任何帮助。

以下是我尝试进行转换的代码部分:

if ($strAdjIncrease == '0') {
    $AdjIncDec == 'Decrease';
} elseif ($strAdjIncrease == '1') {
    $AdjIncDec == 'Increase';
} else {
    $AdjIncDec == 'Unknown';
}
if ($strAdjStatus == '0') {
     $Status =='Open';
} elseif ($strAdjStatus == '1') {
     $Status =='Closed';
} else {
     $Status =='Void';
}

这是我的全表代码:

if (odbc_num_rows($rsIaL) == 0) {
      echo "<center>";
      echo "<b>We're Sorry, No Records Returned.</b><br>\n";
      echo "</center>";
  } else {
      echo "<p align='center'>";
      echo "<font face='Arial' size='4'><b>Last 31 Days Only</b></font>";
      echo "</p>\n";
      echo "<table border='1' align='center' cellpadding='2' style='border-collapse: collapse; font-size: 12px; font-weight: bold'>\n";
      echo "<thead>";
      echo "<tr>";
      echo "<th ALIGN='LEFT' bgcolor='#C0C0C0'><font face='Arial' size='2'><b>#</b></font></th>";
      echo "<th ALIGN='LEFT' bgcolor='#C0C0C0'><font face='Arial' size='2'><b>Log ID</b></font></th>";
      echo "<th ALIGN='LEFT' bgcolor='#C0C0C0'><font face='Arial' size='2'><b>Reason</b></font></th>";
      echo "<th ALIGN='LEFT' bgcolor='#C0C0C0'><font face='Arial' size='2'><b>Inc/Dec</b></font></th>";
      echo "<th ALIGN='LEFT' bgcolor='#C0C0C0'><font face='Arial' size='2'><b>Status</b></font></th>";
      echo "<th ALIGN='LEFT' bgcolor='#C0C0C0'><font face='Arial' size='2'><b>Ref No</b></font></th>";
      echo "<th ALIGN='LEFT' bgcolor='#C0C0C0'><font face='Arial' size='2'><b>Tot Cost</b></font></th>";
      echo "<th ALIGN='LEFT' bgcolor='#C0C0C0'><font face='Arial' size='2'><b>Tot Retail</b></font></th>";
      echo "<th ALIGN='LEFT' bgcolor='#C0C0C0'><font face='Arial' size='2'><b>Start</b></font></th>";
      echo "<th ALIGN='LEFT' bgcolor='#C0C0C0'><font face='Arial' size='2'><b>End</b></font></th>";
      echo "<th ALIGN='LEFT' bgcolor='#C0C0C0'><font face='Arial' size='2'><b>User</b></font></th>";
      echo "</tr>";
      echo "</thead>";
      echo "<tbody>";
      $counter = 1;

      while ($row = odbc_fetch_array($rsIaL)) {
          $strAdjID        = trim(odbc_result($rsIaL, "AdjID"));
          $strReaDesc      = trim(odbc_result($rsIaL, "ReaDesc"));
          $strAdjStatus    = trim(odbc_result($rsIaL, "AdjStatus"));
          $strAdjRefNo     = trim(odbc_result($rsIaL, "AdjRefNo"));
          $strAdjStTS      = trim(odbc_result($rsIaL, "AdjStTS"));
          $strAdjEndTS     = trim(odbc_result($rsIaL, "AdjEndTS"));
          $strAdjUID       = trim(odbc_result($rsIaL, "AdjUID"));
          $strAdjTotCost   = trim(odbc_result($rsIaL, "AdjTotCost"));
          $strAdjTotRetail = trim(odbc_result($rsIaL, "AdjTotRetail"));
          $strAdjIncrease  = trim(odbc_result($rsIaL, "AdjIncrease"));

          if ($bgcolor == '#ffffff') {
              $bgcolor = '#dddddd';
          } else {
              $bgcolor = '#ffffff';
          }
          /*
           I can't get this if/else portion to work and output correctly to the table!
           I may be doing it incorrectly though

          if ($strAdjIncrease == '0') {
              $AdjIncDec == 'Decrease';
          } elseif ($strAdjIncrease == '1') {
              $AdjIncDec == 'Increase';
          } else {
              $AdjIncDec == 'Unknown';
          }
          if ($strAdjStatus == '0') {
              $Status =='Open';
          } elseif ($strAdjStatus == '1') {
              $Status =='Closed';
          } else {
              $Status =='Void';
          }
          */

          echo "<tr>\n";
          echo "<td bgcolor = '$bgcolor' align=center>$counter</td>\n";
          echo "<td bgcolor = '$bgcolor' align=center> <a href='Inventory_Adjustments_Detail.asp?log_id=$strAdjID&store_id=$storeID'>$strAdjID</a></td>\n";
          echo "<td bgcolor = '$bgcolor' align=left>$strReaDesc</td>\n";
          echo "<td bgcolor = '$bgcolor' align=left>$strAdjIncrease</td>\n"; #$AdjIncDec <-if/else variable
          echo "<td bgcolor = '$bgcolor' align=left>".$strAdjStatus."</td>\n"; #$Status <- if/else variable
          echo "<td bgcolor = '$bgcolor' align=left>$strAdjRefNo</td>\n";
          echo "<td bgcolor = '$bgcolor' align=right>$" . number_format($strAdjTotCost, 2) . "</td>\n";
          echo "<td bgcolor = '$bgcolor' align=right>$" . number_format($strAdjTotRetail, 2) . "</td>\n";
          echo "<td bgcolor = '$bgcolor' align=center>" . date('n-j-Y h:i:s A', strtotime($strAdjStTS)) . "</td>\n";
          echo "<td bgcolor = '$bgcolor' align=center>" . date('n-j-Y h:i:s A', strtotime($strAdjEndTS)) . "</td>\n";
          echo "<td bgcolor = '$bgcolor' align=left>$strAdjUID</td>\n";
          echo "</tr>";
          $counter++;
      }

      echo "</tbody>\n";
      echo "</table><br>\n";

  }

1 个答案:

答案 0 :(得分:1)

说实话,我不太了解你的代码......但这里有一些想法:

  1. 尝试在if / else语句之前回显变量$strAdjIncrease$strAdjStatus,以测试它们具有的值 - debug。也许这个错误就在某个地方。

  2. 我不知道这是一个错字还是你想要做的但是我相信 if / else语句中的$AdjIncDec == 'Increase';(以及其他变量)不应该等于==,而应该是=

  3. 在if / else语句中尝试===而不是==