How grouping data with php and display it inside table (table in table)?
<p>I have problem when grouping data table in table.
I've made ​​but I think the results are not in accordance with the expected.</p>

<p><strong>This is the example script :</strong></p>

<pre><code>&lt;?php

$conn=mysql_connect('localhost','root',''); 
mysql_select_db('things',$conn) or die ("Database Not Found"); 
$result = mysql_query("SELECT id, name, size, color FROM things ORDER BY color");  
$state = -1;
$no = 1;    

echo '&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt;INDEX OF COLOR&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;';

    while($row = mysql_fetch_array( $result )) {

        if($state!= $row['color']) {
            $no = 1;
            echo '&lt;tr bgcolor=yellow&gt;&lt;td&gt;'.$row['color']."&lt;/td&gt;&lt;/tr&gt;";
            echo '&lt;tr&gt;&lt;td&gt;&lt;table border=1&gt;&lt;tr&gt;&lt;th&gt;no&lt;/th&gt;&lt;th&gt;NAME OF HERO&lt;/th&gt;&lt;/tr&gt;';
            $state = $row['color'];
        }

        echo '&lt;tr&gt;&lt;td&gt;'.$no.'&lt;/td&gt;&lt;td&gt;'.$row['name'].'&lt;/td&gt;&lt;/tr&gt;';




        $no++;

    } 

    echo '&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;';  

?&gt;
</code></pre>

<p>That code produces the wrong table in the table. The desired outcome is the Color Group>> Details (Table).</p>

<p>I need result like this :)</p>

<pre><code>+-------------------+
| INDEX OF COLOR    |
+-------------------+
|RED                |
+-------------------+
| +----------+      |
| |HERO      |      |
| +----------+      |
| |ROBIN     |      |
| +----------+      |
| |INCREDIBLE|      |
| +----------+      | 
+-------------------+
|BLUE               |
+-------------------+
| +----------+      |
| |HERO      |      |
| +----------+      |
| |SPIDEY    |      |
| +----------+      |
| |SUPER MAN |      |
| +----------+      |   
| |ICE MAN   |      | 
| +----------+      |
+-------------------+
</code></pre>

<p>can anyone help me, why this code wrong?
Thank you. :)</p>
