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

  • Home
  • SEARCH
  • 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 6664561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:37:28+00:00 2026-05-26T02:37:28+00:00

I have managed to display data in one column table, but would like to

  • 0

I have managed to display data in one column table, but would like to have two column instead. Is there a way of doing it? Here’s the code I currently have. Although, it works, it prints in one long column and would like to break it into two columns.

As you can tell, I’m using jQuery Datatable.

<?php
include('config.php');
mysql_connect($host, $username, $password) or die(mysql_error()) ;
mysql_select_db('people') or die(mysql_error()) ;

$data = mysql_query("SELECT * FROM names ORDER BY RAND() LIMIT 20") or die(mysql_error());
?>
<html>
<head>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    <script src="datatables/dt/media/js/jquery.dataTables.js">
    </script>
    <style type="text/css">
      /* @import "datatables/dt/media/css/demo_table.css";

     .result_container{
       width: 553;
      } */
      </style>
    <script>
      $(document).ready(function(){
        $('#the_table').dataTable();
      });
    </script>

</head>

<body>

 <?php

    echo "<table id=\"the_table\">
                     <thead>
                            <tr>
                                <th>Latest names</th>

                            </tr>

                      </thead>

                      <tbody> ";

        while($info = mysql_fetch_array( $data )){

           echo"<tr> <td>" . $info['name'] . "</td> 
                </tr>";                     

            }
            echo" </tbody> ";
      echo "</table> ";
?>
     </body>
</html>  

Any help will be appreciated very much.

  • 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-26T02:37:29+00:00Added an answer on May 26, 2026 at 2:37 am

    echo "<table id=\"the_table\">
          <thead>
             <tr>
          <th>Latest names</th>
        </tr>
          </thead>
    
          <tbody>
    
          <tr>"; 
    
    
    while($info = mysql_fetch_array( $data )){
    
    
    // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row:  
    if( ($c % 2) == 0 && $c != 0){
    echo "</tr><tr>";
    }
    
    
    echo "<td>" . $info['name'] . "</td>";
    
    $c++; 
    
    } // while..
    
    
    // in case you need to fill a last empty cell:
    if ( ( $i % 2 ) != 0 ){
    
    // str_repeat() will be handy when you want more than 2 columns
      echo str_repeat( "<td>&nbsp;</td>", ( 2 - ( $i % 2 ) ) );
    }
    
    
    echo "</tr>
          </tbody>
          </table>";
    

    ?>

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

Sidebar

Related Questions

I have three level hierarchical data. using the statement below i managed to display
i have three tables i would like to link in this one query. The
I’m trying to display two columns in my table view, one being a title
I have a simple application that fetches some data from ONE table on db
I have a UIViewController that manages the display of some data. When the user
I have two forms on one page: a results form and a search form.
I currently have a view, manage, that lists data items. Instead of running edit
I'm new to ASP.NET, C# and the MVC framework but have managed to build
I have a table view where cells can display a variable amount of information.
I have a single-threaded linux app which I would like to make parallel. It

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.