如何从数据库中列出所有DISTINCT产品 [英] How to list DISTINCT ALL products from database

查看:107
本文介绍了如何从数据库中列出所有DISTINCT产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,当用户打开此网页时,数据库中的所有产品都列在该页面上.有些产品显示在多个类别中,这意味着它们被多次列出,如何限制它们只出现一次?

Currently when a user would open this web page, all of the products in the database are listed on the page. Some products show up in multiple categories which means that they are listed multiple times, how can I limit them to showing up once?

推荐答案

在这里,您可以看到一些有关如何从数据库中选择随机记录的示例.但是,请记住,所描述的方法不是最有效的方法.

Here you can see some examples on how you can choose random records from database. However, keep that in mind, that described method is not the most efficient one.

http://www.mysqltutorial.org/select-random -records-database-table.aspx

在您的示例中,它只需要是:

In your example, it would just need to be:

 $query = "SELECT * FROM product WHERE product_status = '1' ORDER BY RAND() LIMIT 12";

这篇关于如何从数据库中列出所有DISTINCT产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆