简体   繁体   English

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

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

I have two tables, both with only one column. 我有两个表,都只有一列。

Table 1:  Merchants
Column:  merchant  (20 entries)

Table 2:  Categories
Column: category  (600 entries)

I'm trying to write a for each loop to select all entries within these two tables and list all possible combinations in this format. 我正在尝试为每个循环编写一个选择这两个表中的所有条目并列出此格式的所有可能组合。 For example.. 例如..

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...

Should I use one mysql command to select the data, then use a for each loop?... or should I run 2 mysql commands and use a nested for each loop on multiple arrays? 我应该使用一个mysql命令来选择数据,然后对每个循环使用一个?...或者我应该运行2个mysql命令并为多个数组上的每个循环使用嵌套?

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

Then do a foreach on the result. 然后对结果做一个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