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.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...