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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:55:05+00:00 2026-06-12T05:55:05+00:00

I have a table showing the list of categories and subcategories, using a function

  • 0

I have a table showing the list of categories and subcategories, using a function to loop through the parent/child tree. Here is the markup of the script:

<table border="1" width="100%" cellspacing="0" cellpadding="2">
    <tr class="dataTableHeadingRow">
        <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
        <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_WEIGHT; ?>&nbsp;</td>
    </tr>
    <tr class="dataTableRow">
    <td class="dataTableContent">
<?php
function category_list( $category_parent_id = 0 )
{
    // NOTE THE ADDITIION OF THE PARENT ID:
    $sql  = 'select cd.categories_name,c.categories_id, c.parent_id, c.sort_order from ' . TABLE_CATEGORIES . ' c, ' . TABLE_CATEGORIES_DESCRIPTION . ' cd where c.categories_id = cd.categories_id AND c.parent_id='.$category_parent_id;
    $res  = tep_db_query( $sql );
    $cats = array();

    while ( $cat = tep_db_fetch_array( $res ) )
    {
        $cats[] = $cat;
    }

   if (count($cats) == 0)
   {
    return '';
   }

    // populate a list items array
    $list_items = array();
    $list_items[] = '<ul>';

    foreach ( $cats as $cat )
    {
        // open the list item
        $list_items[] = '<li>';

        // construct the category link

        $list_items[] = $cat['categories_name'];

        // recurse into the child list
        $list_items[] = category_list( $cat['categories_id'] );

        // close the list item
        $list_items[] = '</li>';
    }
    $list_items[] = '</ul>';

    // convert to a string
    return implode( '', $list_items );

}  

echo category_list();
?>
        </td>
        <td class="dataTableContent"></td>
    </tr>
</table>

Instead of printing as a list all in one <td>, how would i print each list element in an individual <td>?

  • 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-12T05:55:06+00:00Added an answer on June 12, 2026 at 5:55 am

    First, remove the php function from the <td> and place it right on top of your table/html.
    Instead of echo category_list();, do $list = category_list();

    Then within HTML, do this:

           <tr class="dataTableRow">
           <?php foreach( $list as $v) { ?>           
             <td class="dataTableContent"><?php echo $v; ?></td> 
             <?php } ?>
    

    Latest Edit:

           <table border="1" width="100%" cellspacing="0" cellpadding="2">
    <tr class="dataTableHeadingRow">
        <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
        <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_WEIGHT; ?>&nbsp;</td>
    </tr>
    <tr class="dataTableRow"><ul> <!-- change #1 -->
    
    <?php
    function category_list( $category_parent_id = 0 )
    {
    // NOTE THE ADDITIION OF THE PARENT ID:
    $sql  = 'select cd.categories_name,c.categories_id, c.parent_id, c.sort_order from ' . TABLE_CATEGORIES . ' c, ' . TABLE_CATEGORIES_DESCRIPTION . ' cd where c.categories_id = cd.categories_id AND c.parent_id='.$category_parent_id;
    $res  = tep_db_query( $sql );
    $cats = array();
    
    while ( $cat = tep_db_fetch_array( $res ) )
      {
        $cats[] = $cat;
      }
    
       if (count($cats) == 0)
        {
      return '';
      }
    
         // populate a list items array
          $list_items = array();
         // $list_items[] = '<ul>'; Change #2
    
          foreach ( $cats as $cat )
         {
        // open the list item
        $list_items[] = '<td class="dataTableContent"><li>'; //Change #3
    
        // construct the category link
    
        $list_items[] = $cat['categories_name'];
    
        // recurse into the child list
        $list_items[] = category_list( $cat['categories_id'] );
    
        // close the list item
        $list_items[] = '</li></td>'; //Change #4
    }
    $list_items[] = '</ul></tr>'; //Change #5
    
    // convert to a string
    return implode( '', $list_items );
    
    }  
    
    echo category_list();
    ?>
    
     <!--remove </tr> change #6 -->
     </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table showing the list of categories and subcategories, using a function
I am using Struts1.3, I have Jsp page which is showing the list of
I have table view which is showing list of files to download. When I
I have a table showing a list of objects; let's call them Employee for
I have a table view that's showing a list of bank transactions. When I
Im showing a table of data using a paginated list, with a search box
When showing data from a mysql table on an php page does it have
I have a table showing information from a mysql table. I have three forms
Suppose I have the following schema: Table: Showing showing_id movie_id theater_id show_date show_time Table:
I'm trying to display a table showing a list of courses. I would like

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.