如何按类别单独搜索结果? MySQL + PHP

Hi!

I didn't get any code that worked. Of course I could have use then wrongly because I'm a beginner. Some told me to use MySQL subqueries other told me to use PHP foreach achieve it. What I want is to show the search results of a keyword separated by groups of categories, something like that:

Search results for Item, 3 itens in 2 categories:

Category 1:

Item 1 Item 10

Category 2:

  • Item 1003

Can someone explain me it as simple as possible.
Thanks n advance!

I use a single request which return name of category for each item and I use PHP to display it

<?php
    $cat;
    while($result = $statement->fetch()) {
        if($result['cat'] !== $cat) {
            $cat = $result['cat'];
            /* display cat */
        }
        /* display items */
    }
?>