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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:02:31+00:00 2026-06-18T08:02:31+00:00

I have a MySql table and I want to list things by type and

  • 0

I have a MySql table and I want to list things by type and insert headers. What type of query would I use?

From This:

| Fluffy   | Harold | cat        | f    | 1993-02-04 | NULL       |
| Claws    | Gwen   | cat        | m    | 1994-03-17 | NULL       |
| Buffy    | Harold | dog        | f    | 1989-05-13 | NULL       |
| Fang     | Benny  | dog        | m    | 1990-08-27 | NULL       |
| Bowser   | Diane  | dog        | m    | 1979-08-31 | 1995-07-29 |
| Chirpy   | Gwen   | bird       | f    | 1998-09-11 | NULL       |
| Whistler | Gwen   | bird       | f    | 1997-12-09 | NULL       |
| Slim     | Benny  | snake      | m    | 1996-04-29 | NULL       |
| Dalli    | Alli   | canine     | m    | 2001-12-20 | NULL       |
| Tara     | David  | canine     | f    | 2002-05-17 | NULL       |
| Mimi     | Alli   | guinea pig | m    | 2004-05-17 | NULL       |

To this:

<h2>Cat</h2>

<ul>
<li>Fluffy</li>
<li>Claws</li>
</ul>

<h2>Dog</h2>

<li>Buffy</li>
<li>Fang</li>
<li>Bowser</li>
</ul>

etc.

  • 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-06-18T08:02:33+00:00Added an answer on June 18, 2026 at 8:02 am

    Don’t try to do all of this with SQL (just do a standard select query), use PHP to group the result, then present it. The best way to do this would be to have an object that will do the grouping for you, as you’ll probably need it more than once. For example, your class could look something like this:

    <?php
    class Arrays
    {
        public static function group($array,$key)
        {
            if(NULL == $array)
                return NULL;
    
            $grouped = NULL;
    
            foreach($array as $item)
            {
                $grouped[$item[$key]][] = $item;
            }
    
            return $grouped;
        }
    }
    ?>
    

    And your use case could be something like:

    <?php
    $result = ...; // The result of your database query.
    
    $grouped_by_type = Arrays::group($result,"type");
    
    foreach($grouped_by_type as $type => $group)
    {
        echo "<h2>".ucwords($type)."</h2>";
        echo "<ul>";
    
        foreach($group as $animal)
        {
            echo "<li>".$animal['first_name']."</li>"; // Assumes the query brought back first_name...
        }
    
        echo "</ul>";
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table: I want to insert values from the MySQL workbench.
I have a huge table from one mysql db, I want to create a
Using MySQL, I want to return a list of parents, from a table that
I have a MySql table where I want to get the count of rows
I have a MySQL table with an auto-incremented integer primary key. I want to
I have a mysql table which columns are post_id and post_msg. Now I want
by default I have one column in MySQL table to be NULL. I want
Basically, I have multiple URL's stored in a MySQL table. I want to pull
I have a table generated by PHP/mysql, I want a user to click the
I have a DATE datatype mysql column in a table. I want to set

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.