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 6595095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:53:43+00:00 2026-05-25T17:53:43+00:00

I am wondering if it’s possible to create a grid-like layout using div’s that

  • 0

I am wondering if it’s possible to create a grid-like layout using div’s that are dynamically created using PHP.

I am creating a product page that will display all products in a PHP database. I want each product to be housed in a div, and 3 divs to display in a row with as many rows as needed to get through all the products.

Something like this:

div              div              div
$row['product1'] $row['product2'] $row['product3']

div              div              div
$row['product4'] $row['product5'] $row['product6']

I would prefer not to use a table. I know how to line divs up using the float and clear properties, but not if they are all being created in a while statement, which makes me think it might not be possible.

So I guess, is this possible without using tables, or should I just stick with that?

  • 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-05-25T17:53:44+00:00Added an answer on May 25, 2026 at 5:53 pm

    This can be done the way you ask, though it isn’t the best way. It’s entirely possible to identify the <div> positions within columns in a while loop:

    // Looping over your results simplified...
    $i = 1;
    while ($results) {
       if ($i % 3 == 1) {
          $div_class = 'left';
       }  
       else if ($i % 3 == 2) {
          $div_class = 'middle';
       }
       else {
          $div_class = 'right';
       }
       $i++;
    
       // output, simplified
       echo "<div class='$div_class'>$row_contents</div>";
    }
    

    Then use your CSS to float and clear as necessary for the left, middle, right classes.

    .left, .middle, .right {
       float: left;
    }
    .left { clear: left; }
    .right { clear: right; }
    

    However,

    Given all of this, I still probably wouldn’t bother with <div>s. Semantically if this is a list of products, you should be listing them in <li> tags. Then just style the <li> to float: left; and make each one 33% the width of the container so you get 3 per line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wondering if anybody out there has any success in using the JDEdwards XMLInterop functionality.
Wondering if anyone here can offer any insight into the ups/downs of using the
Wondering if there is a way to change the object on the heap that
Wondering if its possible to Moq the Prism EventAggregator Let's take the EventAggregator Quickstart
Wondering if I'm barking up the wrong tree. I'd like a recursive function to
Wondering if it is possible to incorporate regular expressions into a SQL statement on
Wondering if anyone out there has ran into this before.... I'd like to use
Wondering if it's possible to print a carriage return without a line feed in
wondering if there's any way to make it so that a list I have
Wondering if someone can answer something that has stumped me. I have a Timer

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.