我有两个表,都只有一列.
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.