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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:09:57+00:00 2026-06-10T23:09:57+00:00

I am not able to get my head around it. I have this database

  • 0

I am not able to get my head around it.

I have this database table:

category_id
category_name
steps_description

Now I want to show in format like this

Catgeory 1
Then all steps under it

Catgory2
then all steps under it

Can I do it with one mysql query?

Please show me how to loop through with PHP.

EDIT:
I have got the data in object format i.e. collection of objects

I want the result like:

for all categories {

<table><tr><th>Catgory Name </th></tr>
<tr> <td>Step1 </td> </tr>
<tr> <td>Step2 </td> </tr>
<tr> <td>Step3 </td> </tr>
</table>
}

Something like that but with one query.

  • 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-10T23:09:58+00:00Added an answer on June 10, 2026 at 11:09 pm

    I’m not sure if I exactly know what you mean, but I will try anyway… .
    I assume, you have many categoriy names within the table which aren’t unique. And you have many steps for each of them. Now you want to make a table for every category.
    If this is right, you can try something like this:

        $db = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8', 'username', 'password', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
        $stmt = $db->query("SELECT * FROM `table`");
    
        $arr_data = array();
        while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            $arr_data[$row['category_name']][] = $row['steps_description'];
        }
        foreach ($arr_data as $cat) {
            foreach ($cat as $step) {
                $str_steps .= '<tr><td>'.$step.'</td></tr>';
            }
            echo '<table>'.$str_steps.'</table>';
            $str_steps = '';
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my head around this one: Say you have two models
I am not able to get my head around extracting the work_history, affiliations and
I am not able to get the hg head or status for a given
not able to get this, can someone help for this LINQ query? select col1,
I'm not able to get this persistence file correct... I do not find any
i tried to search this but was not able to get any proper help.I
This seems like a repeated question but i'm not able to get my answer.
I have few Question for which I am not able to get a proper
I know this is simple but I am not able to get it right
I want to position two ImageViews horizontally, but I am not able to get

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.