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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:58:41+00:00 2026-05-19T10:58:41+00:00

Ive a table like this global_id | auto_trans | add_drivers |child_seat | booster_seat |

  • 0

I”ve a table like this

global_id | auto_trans | add_drivers |child_seat | booster_seat | day   
- - - - - - - -  - - - - - - - -- -- -  - - - - - - --  - - - - - - - -
   18           2          1             5              2          2
- - - - - -  - - - - - - - - - - - - - - - - - - - - -  - - - - - - -  -
   19           5          8             7              6          1 
- - - - - - - -  - - - - - -  - - -  -  - - - - -  - - - - - - - - -  -
   20           2          4             7              9          3
 - - - - - - - - -  -- -  - - - - - -  - - - - - - - -  - - - - - - -  -

I want to display the values in a table in the below format

 ___________|__1_|_2_ |_3 |
  |         |    |    |   |
auto_trans  | 5  | 2  | 2 |
- - - - -  - - - - -  - - -
add_drivers | 8  | 1  | 4 |
 -- -  - - -  - - - - - --
child_seat  | 7  | 5  | 7 |
 - - -  - - - - - - - - - -
booster_seat| 6  | 2  | 9 |
 - - - - - - - - - - - - - -

How to write loop for this?

  • 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-19T10:58:42+00:00Added an answer on May 19, 2026 at 10:58 am

    The easy answer? By creating a loop in a loop that’ll store the value of a columnname by columnname, instead of what row it is in in the database (see below for an example if you’re in a pickle and need this solved ASAP). The correct answer, however, is that you probably need to normalise your database a little further. Although the values seem to be related, your request to print them in this way tells me your database might be a little off.

    <?php
    /** Just assuming. */
    $results = $db->query( 
        'SELECT auto_trans, add_drivers, child_seat, booster_seat ORDER BY auto_trans' 
    )->fetchAll( );
    
    $categorised = array( );
    foreach( $results as $result ) {
        foreach( $result as $columname => $value ) {
            if( !array_key_exists( $columnname, $categorised ) ) {
                $categories[$columnname] = array( );
            }
            $categories[$columnname][] = $value;
        }
    }
    
    echo "<table>";
    echo "<tr>";
    foreach( $categories as $category => $values ) {
        echo "<tr>";
        echo "<th>" . $category . "</th>";
        foreach( $values as $value ) {
            echo "<td>" . $value . "</td>";
        }
        echo "</tr>";
    }
    echo "</table>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive got table with null values in it. I would like to copy this
I would like to display some values from custom tables in wordpress. This is
I've an old table like this: user> id | name | address | comments
I've created a table like this : create table tbl( address varchar(5000)); If i
I've got a table that looks like this: CREATE TABLE CustomerXmlData (CustomerId int, CustomerData
I've got a situation like this: Table: FunTable ItemKey ItemName ItemPriceEffectiveDate ItemPrice 11 ItemA
I've got a table of student information in MySQL that looks like this (simplified):
I'm relatively confused about this... I've got a table like: +----------------+--------------------------------------------------+------+-----+-------------------+-----------------------------+ | Field |
I've got m2m relationship like this: #main table CREATE TABLE products_product ( id integer
I've few tables like this in the same page: <table> <tr class=head> <th> Brand

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.