...

View Full Version : where/how to put closing div on loop



turpentyne
07-29-2012, 03:06 AM
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

// 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";

}


?>

firepages
07-29-2012, 03:28 AM
you need to echo the closing div but not the first time...


<?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";

}


?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum