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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:27:22+00:00 2026-05-15T19:27:22+00:00

I have simple table that has about 80 rows, which I populate dynamically using

  • 0

I have simple table that has about 80 rows, which I populate dynamically using PHP. What I am trying to do is to layout those rows in chunks for each column. So if I have 80 rows, I would like 4 columns of 20 rows or so, maybe the last column has less or more depending on the total number of rows. The total number of rows can change!

I am having trouble coming up with an implementation method that will not get messy! Anyone know of a simple way that I can implement this.

I have tried using a counter as I loop the data to populate the table and when a multiple of of 20 is reached move to the next block but that didn’t work for me as I had extra rows left over.

foreach($indexes as $index){

    $counter++;

    echo '<tr>';

    if($counter > 20){

        $multiplier = $counter / 20;

        $head = '<td></td>';

        for($i=1; $i<$multiplier; $i++){

            $head .= '<td></td>';

        }

    }

    if($counter < 20){

        $head = ''; 

    }

    echo "$head<td>$index</td><td><input id='$index' name='$index' type='checkbox' /></td>";  

    echo '</tr>';

}

Thanks all for any help

  • 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-15T19:27:23+00:00Added an answer on May 15, 2026 at 7:27 pm

    I would do :

    $nbCols = 4;
    $nbRows = count($indexes)/$nbCols;
    for($row=0; $row<$nbRows; $row++) {
        echo "<tr>";
        for($i=0; $i<$nbCols; $i++) {
            $index = $indexes[$row + ($i*$nbRows)];
            echo "<td>$index</td><td><input id='$index' name='$index' type='checkbox' /></td>";
        }
        echo "</tr>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple table that has this structure: <table> <thead> <tr> <td>Some info</td>
I have a simple table (lets call it Table1) that has a NVARCHAR field
I have a simple cakephp app with table articles that has a cat_id column
Using MySQL, I have a simple table that logs the IP Address that users
If I have a simple table where the data is such that the rows
I'm trying to have a simple html table, that highlights a row as a
I have a simple procedure that selects 1000 rows from a table. For the
We have a table that has a blob column along with other simple fields.
Back story i have a table that stores cached times, and currently has about
I have a table in my android app that is very simple. Has an

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.