title: Group mysql results by category and display them into groups under each category
body: <p>I am trying to create a simple css menu that gets the data from a mysql table.</p>
  
  <p>My idea is to have menu like this</p>
  
  <pre><code>    Category 1
      - link 1
      - link 2
      - link 3
      Category 2
      - link 1
      - link 2
      - ect...
  </code></pre>
  
  <p>every link has a field named "category". So I want to group and display the links in the menu per category.</p>
  
  <p>I have mysql grouping like</p>
  
  <pre><code>$sql = "SELECT * FROM content group by category";
  $result = mysql_query($sql); 
  </code></pre>
  
  <p>and then I have the html like this</p>
  
  <pre><code>&lt;ul class="menu"&gt;
      &lt;li id="category1" class="files"&gt;
           &lt;a href="#category1"&gt;Category 1&lt;/a&gt;
           &lt;ul class="sub-menu"&gt;
               &lt;li&gt;&lt;a href="#"&gt;link 1&lt;/li&gt;
               &lt;li&gt;&lt;a href="#"&gt;link 2&lt;/li&gt;
               &lt;li&gt;&lt;a href="#"&gt;link 3&lt;/li&gt;
           &lt;/ul&gt;
       &lt;/li&gt;
      &lt;li id="category2" class="files"&gt;
           &lt;a href="#category2"&gt;Category 2&lt;/a&gt;
           &lt;ul class="sub-menu"&gt;
               &lt;li&gt;&lt;a href="#"&gt;link 1&lt;/li&gt;
               &lt;li&gt;&lt;a href="#"&gt;link 2&lt;/li&gt;
               &lt;li&gt;&lt;a href="#"&gt;link 3&lt;/li&gt;
           &lt;/ul&gt;
       &lt;/li&gt;
   &lt;/ul&gt;
  </code></pre>
  
  <p>The db table looks like this</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `content` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `menu_name` text,
    `menu_name_en` text,
    `menu_url` varchar(255) NOT NULL DEFAULT '',
    `header_name` text,
    `header_name_en` enum('MEDIA','GENERAL') NOT NULL DEFAULT 'MEDIA',
    `text` longtext NOT NULL,
    `text_en` text,
    `category` enum('Category 1', 'Category 2') NOT NULL DEFAULT 'Category 1',
    `date` date NOT NULL DEFAULT '0000-00-00',
    `visible` char(1) NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`)
  );
  
  INSERT INTO content (id, menu_name, menu_name_en, menu_url, header_name, header_name_en, text, text_en, category, date, visible) VALUES (26, 'test name', '', 'test_url', 'test name', '', '&lt;p&gt;test text&lt;/p&gt;', '&lt;p&gt;text text&lt;/p&gt;', 'MEDIA', '2014-02-23', '1');
  </code></pre>
  
  <p>So, I am having troubles putting the results in the loop and creating the html by category.</p>
  
  <p>I read many posts here with similar content but couldn't achieve the result I wanted.
  Any help will be much appreciated. Thanks!</p>