Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts

    where/how to put closing div on loop

    I've got a loop working that puts my query results into groupings within div tags, but I'm not sure how to get a closing div in on each category... I guess what I would need is the same thing as the snippet that creates the category header, but for a 'footer'

    seems simple enough, but I'm not sure :

    PHP Code:
    <?php

    // create loop, then...

    while($row mysql_fetch_assoc($result))
    {
        if(
    $category != $row['component_category'])
        {
            
    $category $row['component_category'];
            echo 
    "
            
             <div id=\"calibers\">
    <a class=\"select-toggler\" href=\"javascript:showHide('caliber-expander');\"> <img src=\"images/structural/red-plus.gif\" style=\"position:relative;top:-2px;\"/> {$row['comp_cat_name']}</a><br>\n"
    ;
        }
        echo 
    "<div style='float:left;padding-right:25px;' width='90'>{$row['component_name']} <br><img src='{$row['image_filepath']}'><br></div>\n";

    }


    ?>

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    you need to echo the closing div but not the first time...
    PHP Code:
    <?php
    // create loop, then...
    while($row mysql_fetch_assoc($result))
    {
        if(
    $category != $row['component_category'])
        {
            
    $category $row['component_category'];
            if(!
    $firstime){
                   echo 
    '</div>';
             }else{
                
    $firstime=true;
             }
            echo 
    "
            
             <div id=\"calibers\">
    <a class=\"select-toggler\" href=\"javascript:showHide('caliber-expander');\"> <img src=\"images/structural/red-plus.gif\" style=\"position:relative;top:-2px;\"/> {$row['comp_cat_name']}</a><br>\n"
    ;
        }
        echo 
    "<div style='float:left;padding-right:25px;' width='90'>{$row['component_name']} <br><img src='{$row['image_filepath']}'><br></div>\n";

    }


    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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