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

如何按类别单独搜索结果?  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!

嗨! h2>

我没有得到任何有用的代码。 当然我可以错误地使用,因为我是初学者。 有些人告诉我使用MySQL子查询,其他告诉我使用PHP foreach实现它。 我想要的是显示由类别组分隔的关键字的搜索结果,类似于: p>

项目 em>的搜索结果,3个有两个类别: p>

类别1: h3>

  • 项目1 li >
  • 第10项 li>

    第2类: h3>
    • 项目1003 li> ul> blockquote>

      有人可以解释我这么简单。
      谢谢提前! p> div>

  • 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 */
        }
    ?>