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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:46:40+00:00 2026-05-24T19:46:40+00:00

I have a MySQL table that contains people’s names. Using PHP, what’s the best

  • 0

I have a MySQL table that contains people’s names.
Using PHP, what’s the best way of dividing these names up and displaying them in 3 columns.

This could be achieved using an HTML table, but would it be possible to do this using only <div>‘s?

I heard that this can be done using the % operator. Would this be the best way, and how would this be done?

  • 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-24T19:46:40+00:00Added an answer on May 24, 2026 at 7:46 pm

    You could do this using the modulus operator, however it’s actually possible with just CSS.

    Using display: inline-block, you can get a good column effect. Take a look at this JSFiddle here. I’m only using JavaScript because I’m lazy; the <div> list would be generated by PHP in your case. If you want to confine them to a certain width, just put them in a container <div> with a fixed width.


    I’ve come up with a solution using tables, which is really what you should be doing (you haven’t given any special use cases). The code is below, as well as a working demo here.

    $columns = 4;       // The number of columns you want.
    
    echo "<table>";     // Open the table
    
    // Main printing loop. change `30` to however many pieces of data you have
    for($i = 0; $i < 30; $i++)
    {
        // If we've reached the end of a row, close it and start another
        if(!($i % $columns))
        {
            if($i > 0)
            {
                echo "</tr>";       // Close the row above this if it's not the first row
            }
    
            echo "<tr>";    // Start a new row
        }
    
        echo "<td>Cell</td>";       // Add a cell and your content
    }
    
    // Close the last row, and the table
    echo "</tr>
    </table>";
    

    And to finish off, we have our column-centric layout, this time going back to divs. There’s some CSS here; this should be put in a separate file, not left inline.

    <?php
    $rows = 10;     // The number of columns you want.
    $numItems = 30;     // Number of rows in each column
    
    // Open the first div. PLEASE put the CSS in a .css file; inline used for brevity
    echo "<div style=\"width: 150px; display: inline-block\">";
    
    // Main printing loop.
    for($i = 0; $i < $numItems; $i++)
    {
        // If we've reached our last row, move over to a new div
        if(!($i % $rows) && $i > 0)
        {
            echo "</div><div style=\"width: 150px; display: inline-block\">";
        }
    
        echo "<div>Cell $i</div>";      // Add a cell and your content
    }
    
    // Close the last div
    echo "</div>";
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is for MySQL and PHP I have a table that contains the following
I'm trying to normalize a mysql database.... I currently have a table that contains
I have a MySQL table that contains the columns id , created_date , and
I have a MySQL database table that contains an Article ID ( primary key
I have a MySQL database with a table that contains usernames and passwords. I
I have a mysql table that contains IPAddress parts TABLE `EndPoints`( `EndPointId` BIGINT(19) UNSIGNED
I have a mysql database, in there I have 1 table. That table contains
I have a mysql table that contains a date field in epoch time format.
I have a MySQL table that contains datetime data stored in it. I need
I have a table in MySQL that contains min and max date values for

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.