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
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..

Link to comment
Share on other sites

<?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++;
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.