我怎样才能将数据库中的项目存储到数组中,但前提是该项目尚未在数组中?
我需要从数据库中获取类别名称并将它们存储到一个数组中,但我不想两次获取相同的类别。有没有办法,一旦我获取类别名称并将其存储到数组中即可跳过该类别并且不再存储它?
I need to grab categories name from my database and store them into an array, but I don't want to grab the same category twice. Is there a way to, once I grab the category name and store it into an array to skip that category and not store it any more?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在原始查询中使用 DISTINCT 怎么样?
http://www .mysqlfaqs.net/mysql-faqs/SQL-Statements/Select-Statement/DISTINCT-在 MySQL 中工作
How about using DISTINCT in your original query?
http://www.mysqlfaqs.net/mysql-faqs/SQL-Statements/Select-Statement/How-does-DISTINCT-work-in-MySQL
如果
DISTINCT
不适合您(也许您有多个查询...),您应该将数组用作集合。使用它来添加到数组中:If
DISTINCT
doesn't work for you (maybe you have multiple queries...), you should use your array as a set. Use this to add to the array:在 MySQL 中,如果我理解你的问题:
In MySQL, if I understand your question: