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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:28:35+00:00 2026-05-23T08:28:35+00:00

Hy, i have a big question … it may sound simple but actually it’s

  • 0

Hy, i have a big question … it may sound simple but actually it’s very complicated

I have two mysql tables :

info_cat (id, name)
info_subcat (id, id_info_cat, name)

I want to show the user the info_cat.name followed by info_subcat.name but the problem is that info_cat.name i want to appear just one time.
Something like this:

Laptop

  • Hp
  • Sony
  • Acer

HDD

  • Western DIgital
  • Seagate
  • ETC

So normaly i will query like this (old fashioned)

$query = mysql_query("SELECT * FROM info_cat");
while ($row = mysql_fetch_assoc($query)) {
$id_info_cat = $row['id'];
echo $row['name']; 
 $query2 = mysql_query("SELECT * FROM info_subcat WHERE id_info_cat = '$id_info_cat'");
 while($row2 = mysql_fetch_assoc($query2)) {
 echo $row2['nume'];
 }
}

and i have while within while.
My question is how can i use only a query to acomplish this (i think with JOIN) ??
I have tried the following command :

SELECT info_cat.name, info_subcat.name AS name2, info_subcat.id FROM info_cat, info_subcat WHERE info_cat.id = info_subcat.id_info_cat;

but can’t figure it out how to manipulate data because it will output :

name       name2                 id
Laptop     Acer                  1
Laptop     HP                    2
Laptop     Sony                  3
HDD        Western Digital       4
HDD        Seagate               5
HDD        ETC                   6

and i just want to echo Laptop one time and HDD one time followed by its subcat names.
How can i do that ?

Pleaseee ….

Thank you

  • 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-23T08:28:35+00:00Added an answer on May 23, 2026 at 8:28 am

    Try using GROUP BY and GROUP_CONCAT.

    SELECT
        info_cat.name,
        GROUP_CONCAT(info_subcat.name ORDER BY info_subcat.name SEPARATOR ', ')
    FROM
        info_cat
            LEFT JOIN
        info_subcat ON (info_car.id = info_subcat.id_info_cat)
    GROUP BY
        info_cat.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hy, I have a very big question . I have an array like this
First of all, I want to say sorry for this very big question, but
I have already asked a similar question earlier but I have notcied that I
I know its a big question but I'm a complete beginner. I've limited experience
I know this is a BIG question, but i am looking to integrate magento
I have a Big O notation question. Say I have a Java program that
I'm maintaining a software developed using J2SE, (but i'm c# developer actually not have
It's a big question but I just need a push in the right direction.
If you have seen my previous questions, you'd already know I am a big
I have big system that make my system crash hard. When I boot up,

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.