```
$myfile = mysql_query($query_myfile, $db) or die(mysql_error());
$totalRows_myfile = mysql_num_rows($myfile);
$typ_d = '';
$test='';

while ( $row_myfile = mysql_fetch_assoc($myfile) ) 
{
   if ( $typ_d != $row_myfile[ 'typ_d' ] ) 
   {

       $typ_d = $row_myfile[ 'typ_d' ];

       echo "<h2>$typ_d</h2>";

   }
   if ( $test != $row_myfile[ 'test' ] ) 
   {

       $test = $row_myfile[ 'test' ];

       echo "<h3>$test</h3>";
   }

   echo "<li><a href=\"myfileDetail.php?myfile_id=".$row_myfile['myfile_id']. "\">";
   echo $row_myfile['shortname'].' ';
   echo $row_myfile['name']; ?></a></li>

   <?php } ?>

```

This code list out element in group and subgroups like this 

Typ\_d (group) generated by 

```
echo "<h2>$typ_d</h2>";

```

test(subgroup) generated by 

```
echo "<h3>$test</h3>";

```

then the lists generated by 

```
echo "<li><a href=\"myfileDetail.php?myfile_id=".$row_myfile['myfile_id']. "\">";
       echo $row_myfile['shortname'].' ';
       echo $row_myfile['name']; ?></a></li>

```

I have a problem generation the html tag as follow

```
<h2>Typ_d1</h2>
<h3> Test1</h3>
<ul>
  <li> List1</li>
  <li> List2 </li>
  <li>List3 </li>
</ul>
<h2>Typ_d2 </h2>
<h3>Test2</h3>
<ul>
  <li> List1</li>
  <li> List2</li>
  <li> List3</li>
</ul>
<h2> Typ_d3</h2>
<h3> Test3</h3>
<ul>
  <li> List1</li>
  <li> List2 </li>
  <li>List3 </li>
</ul>

```

I have tried so much but i cannot get it with the right order ..need help please

the current out put has not <`ul`> tag and I would like to put it in side the code

this is the current output

```
<li> List1</li>
  <li> List2 </li>
  <li>List3 </li>

<h2>Typ_d2 </h2>
<h3>Test2</h3>

  <li> List1</li>
  <li> List2</li>
  <li> List3</li>

<h2> Typ_d3</h2>
<h3> Test3</h3>

  <li> List1</li>
  <li> List2 </li>
  <li>List3 </li>

```