繁体   English   中英

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

[英]php foreach loop on mysql data from 2 tables?

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

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。

SELECT table1.(put the star sign), table2.(put the star sign)
FROM table1
INNER JOIN table2 ON 1=1

使用外连接,

SELECT * FROM Merchants, Categories    //Number of Records:20 X 600

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM