Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-29-2012, 02:06 AM   PM User | #1
turpentyne
Regular Coder

 
Join Date: Aug 2010
Posts: 309
Thanks: 10
Thanked 1 Time in 1 Post
turpentyne is an unknown quantity at this point
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";

}


?>
turpentyne is offline   Reply With Quote
Old 07-29-2012, 02:28 AM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,896
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
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)
firepages is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:20 PM.


Advertisement
Log in to turn off these ads.