PHP if statement help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ebarton
Forum Newbie
Posts: 2
Joined: Wed Mar 02, 2005 10:15 pm

PHP if statement help

Post 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;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hint: !=
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

infolock, you forgot to notice that the assignment of $previous_main is in the loop ;)
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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:
Post Reply