Page 1 of 1

PHP if statement help

Posted: Wed Mar 02, 2005 10:22 pm
by ebarton
I am reading a "main category" table and "subcategory" table then trying to write out the main category in H2 tags, then write the subcategories below it. For some reason, the if statement does not recognize when the main category is changing ( if (!$record["Main"] == $previous_main) ). Does anyone now why or know of an effective way of doing this?

Thanks... Ernest

Code: Select all

$result = mysql_query("SELECT mcat .mcat_name AS Main, scat .scat_name AS Sub
                              FROM mcat INNER JOIN scat ON mcat.mcatID  = scat .maincat");

       $previous_main = "";
       while ($record = mysql_fetch_assoc($result)) {
              if (!$recordї"Main"] == $previous_main) {
              echo "<h2>".$record&#1111;"Main"]."</h2>";
	      &#125;
	      echo <font color='red'>".$record&#1111;"Sub"]."</font> <br><br>";
          $previous_main = $record&#1111;"Main"];
	   &#125;

Posted: Wed Mar 02, 2005 11:04 pm
by feyd
hint: !=

Posted: Wed Mar 02, 2005 11:49 pm
by feyd
infolock, you forgot to notice that the assignment of $previous_main is in the loop ;)

Posted: Wed Mar 02, 2005 11:52 pm
by infolock
it is? looks to me as though it's outside of it...

edit : oops ;) missed that last little part haha. my bad. i'll remove the post then.. playing jet set poker AND party poker and surfing the boards hah.. :oops: