Scott Kowalski
Scott Kowalski

Reputation: 9

Simple If/else statement

Revised Code of full deal.. instead of just the small snippet.. Would $row be the start of the variable?

 <?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>";
      }

       ?>

Upvotes: 0

Views: 79

Answers (2)

Ben
Ben

Reputation: 1061

Everyone accidentally does it when they begin programming. You've wrote one ='s sign to check for equality but all that is doing is assign it therefore it will always be true(unless it's a constant). Use two ='s for equality, three '='s for type, one '=' for an assignment.

Upvotes: 0

Anemoia
Anemoia

Reputation: 8116

Assuming this is PHP, use the == for equality checks. If you also want to do type checks use the === (recommended).

Also, you might want to look at the boolean data type for this, this is a simple true/false.

Upvotes: 1

Related Questions