I have a list of id like this from mysql

JM.1
JM.2
JM.2.1
JM.2.2
JM.2.1.0
JM.2.1.1
JM.3
...
...etc

I want to make a display as well
JM.1
JM.2
---JM.2.1
---JM.2.2
---------JM.2.1.0
---------JM.2.1.1
JM.3
...
...etc

How to display using PHP and How To using CSS like that, Or is there who has a reference?

Member Avatar for iamthwee

Easiest might be to store them in table as parent and child then recurse through them.

Member Avatar for diafol

You could use something like this:

$dotdash = array(2=>3,3=>9);

$array = array('JM.1','JM.2','JM.2.1','JM.2.2','JM.2.1.0','JM.2.1.1','JM.3');

foreach($array as $item)
{
    $dots = substr_count($item,'.');
    $add = (isset($dotdash[$dots])) ? str_repeat('-',$dotdash[$dots]) : '';
    echo $add . $item .  '<br />';   
}

OUTPUT:

JM.1
JM.2
---JM.2.1
---JM.2.2
---------JM.2.1.0
---------JM.2.1.1
JM.3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.