微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php foreach循环来自2个表的mysql数据?

我有两个表,都只有一列.

Table 1:  Merchants
Column:  merchant  (20 entries)

Table 2:  Categories
Column: category  (600 entries)

我正在尝试为每个循环编写一个选择这两个表中的所有条目并列出此格式的所有可能组合.例如..

merchant1 category1
merchant1 category2
merchant1 category3... all the way to end of categories
merchant2 category1
merchant2 category2
merchant2 category3...all the way to end of categories
etc...

我应该使用一个MySQL命令来选择数据,然后对每个循环使用一个?…或者我应该运行2个MySQL命令并为多个数组上的每个循环使用嵌套?

解决方法:

SELECT `Merchants`.`merchant`, `Categories`.`category`
FROM `Merchants`
JOIN `Categories`;

然后对结果做一个foreach.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐