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?

Recommended Answers

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

Jump to Post

All 2 Replies

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

Member Avatar

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.