I am trying to create a loop in php to display a list of categories the loop is working fine and sql queries pulls all the correct information however I'm trying to echo out a <p>
tag for every 4 times the loop increments, this creates a new line on my site design. How ever the issue being when I echo a p tag using echo '<p>';
it creates a closing tag straight after.
Here is my code:
echo '<!-- Create first 4 --><P>';
while($row1 = mysql_fetch_array($result1))
{
echo '<div class="cat">';
echo '<img src="'.$row1['IMAGE'].'" alt="'.$row1['NAME'].'">';
echo '<h2>'.$row1['NAME'].'</h2>';
echo '</div>';
$i++;
//force a new line of catagories
if (( $i == 4 )||( $i == 8 )||( $i == 12 ))
{
echo '<!-- if more than 4 Close first 4 --></p>';
echo '<!-- Create second 4 --><p>';
}
}
echo '<!-- close first 4 --></p>';
When this is run in firefox and i check the source code i get this:
<div class="content">
<!-- Create first 4 -->
<p></p><div class="cat"> … </div><div class="cat"> … </div><div class="cat"> … </div><div class="cat"> … </div>
<!-- if more than 4 Close first 4 -->
<p></p>
<!-- Create second 4 -->
<p></p><div class="cat"> … </div><div class="cat"> … </div><div class="cat"> … </div><div class="cat"> … </div>
<!-- if more than 4 Close first 4 -->
<p></p>
<!-- Create second 4 -->
<p> … </p></div>
I need it to print exactly what is inside the echo statements.