SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP IF statement. hierarchical data problems

    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

    $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["Main"]."</h2>";
    }
    echo <font color='red'>".$record["Sub"]."</font> <br><br>";
    $previous_main = $record["Main"];
    }

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if ($record["Main"] != $previous_main) {


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •