Query product images

Source: Internet
Author: User
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 isgoodsThe image table isimagesTo obtain the imageidIs 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_IMPUTEDThe product you want to specifyidValue.

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

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.