简单的If / else语句

时间:2014-10-13 14:44:29

标签: if-statement

修改完整代码...而不只是小片段.. $ row是变量的开头吗?

 <?php
   error_reporting(-1);
   $sql = "SELECT * FROM products Where available like 'Y%'  order by manufacturer2, product ASC";
   $query = mysql_query($sql);
   while($row = mysql_fetch_array($query)) {

<--------------------->> $new_product = "$row"; if ($new_product == "N") { echo "No"; } elseif ($new_product == "Y") { echo "Yes"; }

<-------->


     echo "<div class=reportsalesnew_product>".$row['new_product']."</div>";
     echo "<div class=reportsalescase_avail>".$row['case_avail']."</div>";
     echo "<div class=reportsalesseasonal>".$row['seasonal']."</div>";
     echo "<div class=reportsaleseigth_bbl>".$row['eigth_bbl']."</div>";
     echo "<div class=reportsalesquarter_bbl>".$row['quarter_bbl']."</div>";
     echo "<div class=reportsaleshalf_bbl>".$row['half_bbl']."</div>";
     echo "<div class=reportsalessixth_bbl>".$row['sixth_bbl']."</div>";
     echo "<div class=reportsalesthirty_liter>".$row['thirty_liter']."</div>";
     echo "<div class=reportsalesfifty_liter>".$row['fifty_liter']."</div>";


      echo "</div>";
      }

       ?>

<?php error_reporting(-1); $sql = "SELECT * FROM products Where available like 'Y%' order by manufacturer2, product ASC"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) {

2 个答案:

答案 0 :(得分:1)

假设这是PHP,请使用==进行equality检查。如果想要进行类型检查,请使用===(推荐)。

另外,您可能需要查看boolean数据类型,这是一个简单的true / false

答案 1 :(得分:0)

每个人在开始编程时都会意外地做到这一点。你已经写了一个='的符号来检查是否相等,但所有正在做的就是分配它,因此它总是为真(除非它是常数)。使用两个='表示相等,三个'='表示类型,一个'='表示赋值。