Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8290665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:52:28+00:00 2026-06-08T12:52:28+00:00

I’m working on a loop within a grid system that displays 2 grid rows

  • 0

I’m working on a loop within a grid system that displays 2 grid rows of 3 inline images at a time (pagination). I’ve been trying to debug my code to display <div id="clear"></div> after every 3 returned MySQL rows, but haven’t been successful.

PHP/HTML

<ul class="clean" style="width:940px; height:465px;">
  <?php
  $result = mysql_query("SELECT * FROM images");
  $i=0;
  //Begin image loop
  while($row = mysql_fetch_array($result)){
  //Start counter
  $i++;
  $n = ($i + 5);
  $class = "";
  $clear = "";

  //Generate classes 
  if (($i % 3) == 1){
      $class = "alpha";
  }
  if (($i % 3) == 0){
      $class = "omega";
  }

  //Generate list items
  if (($n % 6) == 0){?>

  <li class="clearfix"> 
    <?php }if (($i % 4) == 0){?>
    <div id="clear"></div>
    <?php }?>
    <div class="grid_4 <?php echo $class;?>">
      <p><a href="<?php echo $row["src"];?>" alt="<?php echo $row["alt"];?>">
      <img src="<?php echo $row["src"];?>" alt="<?php echo $row["alt"];?>" />
      </a><br />
      <small class="center"><?php echo $row["excerpt"];?></small></p>
    </div>
    <?php if (($i % 6) == 0){?>
  </li> 
  <!-- //slide --> 
  <?php }} //End image loop?>
</ul>

How I have my grid set up is, within each grid row from left to right, there is an alpha class assigned to the first element and an omega class assigned to the last. In order to display <div id="clear"></div> after every 3 returned MySQL rows technically, this should work:

Generated list items

<?php 
if (($n % 6) == 0){?>

<li class="clearfix"> 
<?php }if (($i % 4) == 0){?>
  <div id="clear"></div>
<?php }?> 

However it doesn’t. Within 6 returned grid rows equaling 18 total images, it generates <div id="clear"></div> fine after MySQL rows 1-3 and after 13-15, but for MySQL rows 6-9,<div id="clear"></div> displays after MySQL row 6 where it should be displaying after 9.

I hope this makes sense, any suggestions would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:52:30+00:00Added an answer on June 8, 2026 at 12:52 pm

    See if something like this would work for you.

    <?php
    $i = 1;
    $result = mysql_query("SELECT * FROM images");
    
    $max_count = mysql_num_rows($result);
    
    if($max_count > 0)
    {
    ?>
    <ul>
    <?php
    while($row = mysql_fetch_array($result)) {
        if($i % 3 == 1) {
            $class = 'alpha';
        } elseif($i % 3 == 0) {
            $class = 'omega';
        } else {
            $class = ''; //Do NOT carry through the loops
        }
    
        if($i % 6 == 1 || $i == 1) {
    ?>
        <li>
    <?php
        }
    ?>
            <div class="grid_4 <?php echo $class ?>">
                <p>
                    <a href="<?php echo $row["src"];?>" alt="<?php echo $row["alt"];?>"><img src="<?php echo $row["src"];?>" alt="<?php echo $row["alt"];?>" /></a>
                    <br />
                    <small class="center"><?php echo $row["excerpt"];?></small>
                </p>
            </div>
    <?php
        if($i % 3 == 0) {
    ?>
            <div class='clear'>&nbsp;</div>
    <?php
        }
    
        if($i % 6 == 0 || $i == $max_count) {
    ?>
        </li>
    <?php
        }
    
        $i++; //Move Row Count Along
    }
    ?>
    </ul>
    <?php
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.