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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:55:45+00:00 2026-05-24T09:55:45+00:00

Hi I need to build a table with two columns from a mySQL table.

  • 0

Hi I need to build a table with two columns from a mySQL table.
Here is what i have now:

<table>
<?php
$sql = "SELECT field1, field2 FROM tblX" 
$result = mysql_query($sql) or die("\nError Retrieving Records.");
while($row = mysql_fetch_array ($result, MYSQL_ASSOC)){?>
<tr>
   <td>
       <?=$row['field1']?> - <?=$row['field2']?>
   </td>
</tr>
<?php }?>
</table>

This will create one column table like so:

1
2
3
4
5

I need the table to be in two columns like this:

1  4
2  5
3

Is this possible if it is how do I do 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-24T09:55:46+00:00Added an answer on May 24, 2026 at 9:55 am

    This should do what you want, if you insist on a table.

    Get the mid point:

    $mid = ceil(mysql_num_rows($result)/2);
    

    Get an array:

    while( $row = mysql_fetch_row($result) ) {
        $list[] = $row; }
    

    Output the rows:

    for( $i = 0; $i < $mid; $i++ ) {
        $itemOne = $list[$i];
        $itemTwo = $list[$i + $mid]; 
        // echo them in two tds.
    }
    

    I agree with marco, though. You could just as easily list items one to $mid in one div, then $mid to the end in another, and use CSS to float the divs side-by-side. Using tables for formatting purposes is evil.

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

Sidebar

Related Questions

I have two table and I need to copy the data across from SRCServiceUsers
I have a project where I need to build a two tables in sql
I need to have two separate pages on the site I'm planning to build
I have a table containing some Timespans (as two TIME columns) Eg: TimeBegin TimeEnd
I would need to build a html table that has a horizontally scrollable column.
I need to build a class that will represent a row in some table
I need to build a function which parses the domain from a URL. So,
I have a table where there will often be two cells with the same
I am using SQL Server 2000 and I have two databases that both replicate
I am about to build an SQL database and I need to get 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.