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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:16:41+00:00 2026-06-12T00:16:41+00:00

Here is the markup of what I have so far: <?php $categories_query = tep_db_query(select

  • 0

Here is the markup of what I have so far:

<?php

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id, c.sort_order, c.date_added, c.last_modified from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id order by c.sort_order ASC");
while ($categories = tep_db_fetch_array($categories_query)){

echo '<tr class="dataTableRow">
<td class="dataTableContent">' . $categories ['categories_name'] . '</td>';
?>

<td class="dataTableContent"></td>

<?php
echo '</tr>';
}
?>

This displays all the categories and subcategories all on a page, but in no order, what i need is for the subcategories to be displayed under the main category. I have some clue as to how i would do it, a link between the sort_order field and the parent_id field. The main categories use the sort_order field as id, and the subccat’s use the parent_id field to sort the category they belong to. Any ideas?

  • 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-12T00:16:42+00:00Added an answer on June 12, 2026 at 12:16 am

    I’m not sure how to do display category tree with single MySQL query, so I’m suggesting to use recursive PHP function:

    <?php
        function showChildCategories($parent) {
           $parent = intval($parent);
    
           // Select only categories with parent_id = $parent
           $categories_query = tep_db_query("select 
                   cd.categories_name,
                   c.categories_id
               from " . TABLE_CATEGORIES . " c, " . 
                   TABLE_CATEGORIES_DESCRIPTION . " cd 
               where c.categories_id = cd.categories_id 
                     and c.parent_id = $parent
               order by c.sort_order ASC");
    
           // Go through all query result rows
           while ($categories = tep_db_fetch_array($categories_query)){
               // Show category name
               echo '<tr class="dataTableRow"><td class="dataTableContent">' . 
                   $categories ['categories_name'] . '</td></tr>';
    
               // Show child categories for current row
               showChildCategories($categories ['categories_id']);
           } // while
        } // function showChildCategories
    
        // Show top-level categories and all their children recursively
        showChildCategories(0);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some markup here that I need to reformat using javascript. Basically, I
Here's my markup: Name: <asp:TextBox ID=txtNewName runat=server ValidationGroup=NewDepartmentValidationGroup /> <asp:RequiredFieldValidator ID=vldtxtNewName runat=server ControlToValidate=txtNewName ErrorMessage=Required
Can I do this without Javascript? Here is the mock markup.. <div id=parent> <div
Okay, so I'm designing this site. Here's the HTML markup of this simple element:
Here is what I am currently doing. PHP echo's out the recent post in
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is a fiddle: http://jsfiddle.net/5s7vv/ What I want to do is have 2 buttons
I have a webapp written in PHP using a MySQL database backend. This question
I have a table, where each row corresponds to a form. While the markup
I have two audio tags in these markup. my problem is that the second

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.