doujiu3768 2019-07-19 14:01
浏览 47

如何将可重复数据记录到数据库中

i have in database tables like this

products
similar_products_product
similar_products_view

in Products

keep record of main product

in similar_products_product

keep record of custom products that you can assignment into main product later one

in similar_products_view

keep record of assignment main product and their similar_products_product

Query to insert into similar_products_view

foreach ($data['similar_products'] as $cat_id => $key) {
            foreach ($key as $similar_product_id) {
                $this->db->query("INSERT INTO " . DB_PREFIX . "similar_products_view SET product_id = '" . (int)$product_id . "', similar_product_id = '" . (int)$similar_product_id . "', category_id = '" . (int)$cat_id . "'");
            }
        }

than i end up with records like this

id    product_id    similar_product_id    category_id
1     10            2                     7
2     10            4                     7
3     10            5                     7
4     10            10                    7
5     10            12                    7
6     10            15                    6
7     10            24                    6
8     10            30                    6

what will be the better way to record this results ? is it something like to be record whole thing for same product_id at one line ?

id    product_id    similar_product_id    category_id
1     10            2,4,5,10,12,15        7,6

but should know with similar_product_id match category_id the record also should be able for DELETE,UPDATE,SELECT by similar_product_id and category_id

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度