作者:遗忘的vbnv | 来源:互联网 | 2023-05-18 04:11
ImcodinginPHPMySQLandhavethefollowingquerytofetchproductsandproductgroupdata:我在PHP
I'm coding in PHP/MySQL and have the following query to fetch products and product group data:
我在PHP / MySQL中编码并具有以下查询来获取产品和产品组数据:
SELECT products.id,products.name,product_groups.id,product_groups.name
FROM products
INNER JOIN product_groups
ON products.id=product_groups.id
WHERE products.name LIKE '%foobar%'
ORDER by product_groups.id ASC
So this query fetches products and orders them by product group. What I would like to have is to display product_groups.name just once for each product grouping. So even if I have ten shoe products, the group name "Shoes" is only displayed once.
因此,此查询获取产品并按产品组对其进行排序。我想要的是每个产品分组只显示一次product_groups.name。因此,即使我有十个鞋类产品,组名“鞋子”也只显示一次。
I'm using the following PHP to print out the results:
我正在使用以下PHP打印出结果:
while ($data = mysql_fetch_array($result))
2 个解决方案