Brandon Gallagher Brandon Gallagher - 7 months ago 35
PHP Question

How to add clearfix to every 3rd post in an sql string

is there a way I can add .clearfix {clear:both;} to every third post from an sql string without messing up the order of posts? cause if you view the source on my page now, this is how each post would look (minus the sql stuff) I need to clear every 3rd post so that my rows line up right, but not sure how to do it. any help would be appreciated

<div class="row block02">
<? **sql stuff**
<div class="col-1-3">
<div class="wrap-col">

<a href="blog.php?post_id=<? echo($result_miniblog['post_id']); ?>"><img src="../images/<? echo($result_miniblog['image']); ?>" alt="<? echo($result_miniblog['image_alt']); ?>" /></a>
<a class="tag" style="color:#2980b9;" href="#"><? echo($result_miniblog['post_category']); ?></a>
<a class="headline" href="blog.php?post_id=<? echo($result_miniblog['post_id']); ?>"><? echo($result_miniblog['post_title']); ?></a>
<a class="byline" href="blah">
<br />John Doe</a>




Within your sql stuff, you probably have an index (or can easily create one) to know which enumeration of the loop you are in currently. If the modulus of the index and your loop is zero, then you print the clearfix.

<? **sql stuff**

  $clearfix = ($your_sql_loop_index %3 === 0) ? 'clearfix' : '';
<div class="col-1-3 <?php echo $clearfix; ?>">