Content Out Of Div PHP PDO
My content of the subcategories is getting out of the div somehow. The first one stays on there but the second, third etc is getting out from it. Any solutions to it?
Solution 1:
This should be rewritten like:
$close_previous = false; // special flag
foreach ($row2 as $row) {
if ($lastcat != $row['cat_id']) {
$lastcat = $row['cat_id'];
// check whether you need to close divs from previous block
if ($close_previous) {
echo '</div>'; // close .panel-body
echo '</div>'; // close .panel-default
} else {
// for the first time you don't need
// to close divs, so here we skip it
$close_previous = true;
}
echo '<div class="panel panel-default"><div class="panel-heading">';
echo $row['subcat_name'];
echo '</div><div class="panel-body">';
}
echo $row['subsubcat_name'];
// add link
echo '<a href="/test.php?id=' . $row['subcategoryid'] . '">Click</a>';
}
// explicitly close last divs block
echo '</div>'; // close .panel-body
echo '</div>'; // close .panel-default
Also it's a good practice to check your generated html-markup to see what is wrong.
Post a Comment for "Content Out Of Div PHP PDO"