A MySQL Union query column is very basic, but very practical.
First read the data table. Data Table class:
-------------------------------
Id cname
-------------------------------
1 men's wear
2 women's leather pants
3 female Cotton
-------------------------------
The class Table stores the product's category name and its serial number.
Data Table product:
-------------------------------
PID ptype pparent
-------------------------------
1 A01 1
2 A21 1
3 B10 2
4 C11 3
5 c01 2
-------------------------------
The product table stores the product name and its category ID (pparent)
All product numbers, names, and categories must be displayed as follows:
-------------------------------
Sequence Number category
-------------------------------
1 A01 men's wear
2 A21 men's wear
3 B10 Women's leather pants
4 C11 Female Cotton
5 c01 Women's leather pants
-------------------------------
Here we will query the product table and read the pname field of the corresponding class table based on the pparent field. The most traditional one can be implemented using two select statements, but the following is a simple implementation of a combined query statement in MySQL:
Select Product. *, class. * from product inner join class on product. pparent = Class. ID where product. PID is not null
In PHP, the records queried in this way are placed in the array, for example:
$ Myrow = mysql_fetch_array (mysql_query ($ SQL ));
In the $ myrow array, fields in product are stored first, and class fields are stored later.
Use print_r to print $ myrow. The result is as follows:
Array (
[0] => 1
[Pid] => 1
[1] => A01
[Ptype] => A01
[2] => 1
[Pparent] => 1
[3] => 1
[ID] => 1
[4] => men's wear
[Cname] => men's wear
......
)