Jump to content

Display hierarchical data in HTML table.


thara

Recommended Posts

I have a mysql table named categories. This is how my categories looks like:

mysql> select * from categories;
    +-------------+--------+----------------------+-------------+
    | category_id | parent | name                 | description |
    +-------------+--------+----------------------+-------------+
    |           1 |   NULL | Products             | NULL        |
    |           2 |      1 | Computers            | NULL        |
    |           3 |      2 | Laptops              | NULL        |
    |           4 |      2 | Desktop Computers    | NULL        |
    |           5 |      2 | Tab PCs              | NULL        |
    |           6 |      2 | CRT Monitors         | NULL        |
    |           7 |      2 | LCD Monitors         | NULL        |
    |           8 |      2 | LED Monitors         | NULL        |
    |           9 |      1 | Mobile Phones        | NULL        |
    |          10 |      9 | LG Phone             | NULL        |
    |          11 |      9 | Anroid Phone         | NULL        |
    |          12 |      9 | Windows Mobile       | NULL        |
    |          13 |      9 | iPad                 | NULL        |
    |          14 |      9 | Samsung Galaxy       | NULL        |
    |          15 |      1 | Digital Cameras      | NULL        |
    |          16 |      1 | Printers and Toners  | NULL        |
    |          22 |      1 | Computer Accessaries | NULL        |
    |          23 |     22 | USB Cables           | NULL        |
    |          24 |     22 | Network Cables       | NULL        |
    +-------------+--------+----------------------+-------------+
    24 rows in set (0.00 sec)

So now I need to display these category and sub categories in a HTML table.

 

I have attached an image with the table layout which is I expect.

 

Can anybody tell me is it possible to do in php?

 

Thank you.

 

post-123452-0-35077600-1444495513_thumb.jpg

Edited by thara
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.