Jump to content

Quick Question: Hopefully simple answer :)


stig1

Recommended Posts

I have a database which i can pull out the required records.

 

However, after every 3 records I would like to put in the following code

 

<div class="clear"></div>

 

So my layout will not look messy.

 

How would I go about doing this?

 

So if there is 13 records pulled out of the database, I should have 3 records, than a clear class and then another 3 records, then another clear class and so on...

Link to comment
https://forums.phpfreaks.com/topic/147499-quick-question-hopefully-simple-answer/
Share on other sites

sorry for double post.. it won't

 

<?php
$a = 0;
while ($row = mysql_fetch_assoc($query)) {
  $a++;
  // do your thing with the results
  if ($a == 3) {
    echo "<div class='clear'></div>";
    $a = 0;
  }
}
?>

 

now it should..

<?php
$a = 0;
while ($row = mysql_fetch_assoc($query)) {
  // do your thing with the results
  if ($a % 3) {
    echo "<div class='clear'></div>";
  }
  $a++;
}
?>

 

I was thinkin about usin a modulus but I don't really care much for redoing code :P

 

and also.. $a % 3 would be true 2/3 times.. so you'd want to do something like:

 

<?php
$a = 0;
while ($row = mysql_fetch_assoc($query)) {
  // do your thing with the results
  if (!($a % 3)) {
    echo "<div class='clear'></div>";
  }
  $a++;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.