There is a commodity table: {code ...} there is an image table for the item: {code ...} there is a one-to-many relationship between the product table and the product image table. How can I find the product information and all the images? There is a commodity table:
+--------------+---------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+--------------+---------------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || cate_id | int(11) | NO | | NULL | || name | varchar(100) | NO | | NULL | || name_extend | varchar(200) | NO | | NULL | || price | decimal(10,2) | NO | | NULL | || origin_price | decimal(10,2) | NO | | NULL | || stock | int(11) | NO | | NULL | || desc | tinytext | NO | | NULL | || detail | text | NO | | NULL | || express | int(11) | NO | | NULL | || status | tinyint(1) | NO | | NULL | || slide | tinyint(1) | NO | | NULL | || is_delete | tinyint(1) | NO | | NULL | || add_time | int(11) | NO | | NULL | |+--------------+---------------+------+-----+---------+----------------+
There is an image table for the item:
+----------+--------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+----------+--------------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || goods_id | int(11) | NO | | NULL | || img_path | varchar(255) | NO | | NULL | || is_main | tinyint(1) | NO | | NULL | || add_time | int(11) | NO | | NULL | |+----------+--------------+------+-----+---------+----------------+
There is a one-to-many relationship between the product table and the product image table. How can I find the product information and all the images?
Reply content:
There is a commodity table:
+--------------+---------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+--------------+---------------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || cate_id | int(11) | NO | | NULL | || name | varchar(100) | NO | | NULL | || name_extend | varchar(200) | NO | | NULL | || price | decimal(10,2) | NO | | NULL | || origin_price | decimal(10,2) | NO | | NULL | || stock | int(11) | NO | | NULL | || desc | tinytext | NO | | NULL | || detail | text | NO | | NULL | || express | int(11) | NO | | NULL | || status | tinyint(1) | NO | | NULL | || slide | tinyint(1) | NO | | NULL | || is_delete | tinyint(1) | NO | | NULL | || add_time | int(11) | NO | | NULL | |+--------------+---------------+------+-----+---------+----------------+
There is an image table for the item:
+----------+--------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+----------+--------------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || goods_id | int(11) | NO | | NULL | || img_path | varchar(255) | NO | | NULL | || is_main | tinyint(1) | NO | | NULL | || add_time | int(11) | NO | | NULL | |+----------+--------------+------+-----+---------+----------------+
There is a one-to-many relationship between the product table and the product image table. How can I find the product information and all the images?
If the item table isgoods
The image table isimages
To obtain the imageid
Is a parameter, then:
SELECT `goods`.`id`, `goods`.`name`, `goods`.`name_extend`, `images`.`img_path` FROM `goods`, `images` WHERE `goods`.`id` = `images`.`goods_id` AND `goods`.`id` = 'ID_IMPUTED';
Note:ID_IMPUTED
The product you want to specifyid
Value.
We recommend that you cancel the image table.
If the attributes of the product image (for example, the Creation Time) are unimportant, we recommend that you cancel the image table.
If the image information does not need to be retrieved, it is directly inserted into exif). Minimize data redundancy.
We recommend that you insert the image id into a column in the product table.
We recommend that you insert the image id to a column in the product table. The image id is the file name. The path is determined by user id and other factors.