Ajutor inserare Json in Mysql

Buna ziua!
Incerc sa obtin baza de date de la GSMArena in baza mea de date MySql (cu acest API) si sa o mentin actualizata
Nu sunt programator asa ca intampin diferite probleme.

Rezultatul la cererea prin API arata in felul acesta:

{
    "status": 200,
    "message": "Success",
    "data": {
        "key": "apple_iphone_13_pro_max-11089",
        "device_name": "Apple iPhone 13 Pro Max",
        "device_image": "https://fdn2.gsmarena.com/vv/bigpic/apple-iphone-13-pro-max.jpg",
        "display_size": "6.7\"",
        "display_res": "1284x2778 pixels",
        "camera": "12MP",
        "video": "2160p",
        "ram": "6GB RAM",
        "chipset": "Apple A15 Bionic",
        "battery": "4352mAh",
        "batteryType": "Li-Ion",
        "release_date": "Released 2021, September 24",
        "body": "240g, 7.7mm thickness",
        "os_type": "iOS 15, up to iOS 15.5",
        "storage": "128GB/256GB/1TB storage, no card slot",
        "comment": "Versions: A2643 (International); A2484 (USA); A2641 (Canada, Japan); A2644 (China, Hong Kong); A2645 (Russia)",
        "more_specification": [
            {
                "title": "Network",
                "data": [
                    {
                        "title": "Technology",
                        "data": [
                            "GSM / CDMA / HSPA / EVDO / LTE / 5G"
                        ]
                    },
                    {
                        "title": "2G bands",
                        "data": [
                            "GSM 850 / 900 / 1800 / 1900 - SIM 1 & SIM 2 (dual-SIM)"
                        ]
                    },
                    {
                        "title": "3G bands",
                        "data": [
                            "HSDPA 850 / 900 / 1700(AWS) / 1900 / 2100"
                        ]
                    },
                    {
                        "title": "4G bands",
                        "data": [
                            "1, 2, 3, 4, 5, 7, 8, 12, 13, 17, 18, 19, 20, 25, 26, 28, 30, 32, 34, 38, 39, 40, 41, 42, 46, 48, 66 - A2643, A2644, A2645"
                        ]
                    },
                    {
                        "title": "5G bands",
                        "data": [
                            "1, 2, 3, 5, 7, 8, 12, 20, 25, 28, 30, 38, 40, 41, 48, 66, 77, 78, 79 SA/NSA/Sub6 - A2643, A2644"
                        ]
                    },
                    {
                        "title": "Speed",
                        "data": [
                            "HSPA 42.2/5.76 Mbps, LTE-A, 5G, EV-DO Rev.A 3.1 Mbps"
                        ]
                    }
                ]
            },
            {
                "title": "Launch",
                "data": [
                    {
                        "title": "Announced",
                        "data": [
                            "2021, September 14"
                        ]
                    },
                    {
                        "title": "Status",
                        "data": [
                            "Available. Released 2021, September 24"
                        ]
                    }
                ]
            },
            {
                "title": "Body",
                "data": [
                    {
                        "title": "Dimensions",
                        "data": [
                            "160.8 x 78.1 x 7.7 mm (6.33 x 3.07 x 0.30 in)"
                        ]
                    },
                    {
                        "title": "Weight",
                        "data": [
                            "240 g (8.47 oz)"
                        ]
                    },
                    {
                        "title": "Build",
                        "data": [
                            "Glass front (Gorilla Glass), glass back (Gorilla Glass), stainless steel frame"
                        ]
                    },
                    {
                        "title": "SIM",
                        "data": [
                            "Single SIM (Nano-SIM and/or eSIM) or Dual SIM (Nano-SIM/eSIM, dual stand-by)"
                        ]
                    }
                ]
            },
            {
                "title": "Display",
                "data": [
                    {
                        "title": "Type",
                        "data": [
                            "Super Retina XDR OLED, 120Hz, HDR10, Dolby Vision, 1000 nits (HBM), 1200 nits (peak)"
                        ]
                    },
                    {
                        "title": "Size",
                        "data": [
                            "6.7 inches, 109.8 cm2 (~87.4% screen-to-body ratio)"
                        ]
                    },
                    {
                        "title": "Resolution",
                        "data": [
                            "1284 x 2778 pixels, 19.5:9 ratio (~458 ppi density)"
                        ]
                    },
                    {
                        "title": "Protection",
                        "data": [
                            "Scratch-resistant ceramic glass, oleophobic coating"
                        ]
                    }
                ]
            },
            {
                "title": "Platform",
                "data": [
                    {
                        "title": "OS",
                        "data": [
                            "iOS 15, up to iOS 15.5, planned upgrade to iOS 16"
                        ]
                    },
                    {
                        "title": "Chipset",
                        "data": [
                            "Apple A15 Bionic (5 nm)"
                        ]
                    },
                    {
                        "title": "CPU",
                        "data": [
                            "Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)"
                        ]
                    },
                    {
                        "title": "GPU",
                        "data": [
                            "Apple GPU (5-core graphics)"
                        ]
                    }
                ]
            },
            {
                "title": "Memory",
                "data": [
                    {
                        "title": "Card slot",
                        "data": [
                            "No"
                        ]
                    },
                    {
                        "title": "Internal",
                        "data": [
                            "128GB 6GB RAM, 256GB 6GB RAM, 512GB 6GB RAM, 1TB 6GB RAM"
                        ]
                    }
                ]
            },
            {
                "title": "Main Camera",
                "data": [
                    {
                        "title": "Quad",
                        "data": [
                            "12 MP, f/1.5, 26mm (wide), 1.9µm, dual pixel PDAF, sensor-shift OIS\n12 MP, f/2.8, 77mm (telephoto), PDAF, OIS, 3x optical zoom\n12 MP, f/1.8, 13mm, 120˚ (ultrawide), PDAF\nTOF 3D LiDAR scanner (depth)"
                        ]
                    },
                    {
                        "title": "Features",
                        "data": [
                            "Dual-LED dual-tone flash, HDR (photo/panorama)"
                        ]
                    },
                    {
                        "title": "Video",
                        "data": [
                            "4K@24/30/60fps, 1080p@30/60/120/240fps, 10-bit HDR, Dolby Vision HDR (up to 60fps), ProRes, Cinematic mode, stereo sound rec."
                        ]
                    }
                ]
            },
            {
                "title": "Selfie camera",
                "data": [
                    {
                        "title": "Dual",
                        "data": [
                            "12 MP, f/2.2, 23mm (wide), 1/3.6\"\nSL 3D, (depth/biometrics sensor)"
                        ]
                    },
                    {
                        "title": "Features",
                        "data": [
                            "HDR"
                        ]
                    },
                    {
                        "title": "Video",
                        "data": [
                            "4K@24/25/30/60fps, 1080p@30/60/120fps, gyro-EIS"
                        ]
                    }
                ]
            },
            {
                "title": "Sound",
                "data": [
                    {
                        "title": "Loudspeaker",
                        "data": [
                            "Yes, with stereo speakers"
                        ]
                    },
                    {
                        "title": "3.5mm jack",
                        "data": [
                            "No"
                        ]
                    }
                ]
            },
            {
                "title": "Comms",
                "data": [
                    {
                        "title": "WLAN",
                        "data": [
                            "Wi-Fi 802.11 a/b/g/n/ac/6, dual-band, hotspot"
                        ]
                    },
                    {
                        "title": "Bluetooth",
                        "data": [
                            "5.0, A2DP, LE"
                        ]
                    },
                    {
                        "title": "GPS",
                        "data": [
                            "Yes, with A-GPS, GLONASS, GALILEO, BDS, QZSS"
                        ]
                    },
                    {
                        "title": "NFC",
                        "data": [
                            "Yes"
                        ]
                    },
                    {
                        "title": "Radio",
                        "data": [
                            "No"
                        ]
                    },
                    {
                        "title": "USB",
                        "data": [
                            "Lightning, USB 2.0"
                        ]
                    }
                ]
            },
            {
                "title": "Features",
                "data": [
                    {
                        "title": "Sensors",
                        "data": [
                            "Face ID, accelerometer, gyro, proximity, compass, barometer"
                        ]
                    }
                ]
            },
            {
                "title": "Battery",
                "data": [
                    {
                        "title": "Type",
                        "data": [
                            "Li-Ion 4352 mAh, non-removable (16.75 Wh)"
                        ]
                    },
                    {
                        "title": "Charging",
                        "data": [
                            "Fast charging (27W, unofficial rating), 50% in 30 min (advertised)\nUSB Power Delivery 2.0\nMagSafe wireless charging 15W\nQi magnetic fast wireless charging 7.5W"
                        ]
                    }
                ]
            },
            {
                "title": "Misc",
                "data": [
                    {
                        "title": "Colors",
                        "data": [
                            "Graphite, Gold, Silver, Sierra Blue, Alpine Green"
                        ]
                    },
                    {
                        "title": "Models",
                        "data": [
                            "A2643, A2484, A2641, A2644, A2645, iphone14,3"
                        ]
                    },
                    {
                        "title": "SAR",
                        "data": [
                            "1.18 W/kg (head)     1.20 W/kg (body)"
                        ]
                    },
                    {
                        "title": "SAR EU",
                        "data": [
                            "0.99 W/kg (head)     0.98 W/kg (body)"
                        ]
                    },
                    {
                        "title": "Price",
                        "data": [
                            "$ 1,027.99 / £ 999.00 / € 1,202.00 / ₹ 126,900 / Rp 23,681,736"
                        ]
                    }
                ]
            },
            {
                "title": "Tests",
                "data": [
                    {
                        "title": "Performance",
                        "data": [
                            "AnTuTu: 801691 (v9)\nGeekBench: 4706 (v5.1)\nGFXBench: 60fps (ES 3.1 onscreen)"
                        ]
                    },
                    {
                        "title": "Display",
                        "data": [
                            "Contrast ratio: Infinite (nominal)"
                        ]
                    },
                    {
                        "title": "Camera",
                        "data": [
                            "Photo / Video"
                        ]
                    },
                    {
                        "title": "Loudspeaker",
                        "data": [
                            "-24.0 LUFS (Very good)"
                        ]
                    },
                    {
                        "title": "Battery life",
                        "data": [
                            "Endurance rating 121h"
                        ]
                    }
                ]
            }
        ],
        "prices": {
            "128GB 6GB RAM": [
                {
                    "shop_image": "https://fdn.gsmarena.com/imgroot/static/stores/ebay-com2.png",
                    "price": "$ 1,027.99",
                    "buy_url": "https://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=2&toolid=10044&campid=5338659500&customid=gsmarena&lgeo=1&vectorid=229466&item=284664052319"
                },
                {
                    "shop_image": "https://fdn.gsmarena.com/imgroot/static/stores/amazon-com1.png",
                    "price": "$ 1,099.00",
                    "buy_url": "https://www.amazon.com/dp/B09G9LN82D?tag=gsmarena093-20&linkCode=osi&th=1&psc=1"
                },
                {
                    "shop_image": "https://fdn.gsmarena.com/imgroot/static/stores/best-buy-1.png",
                    "price": "$ 1,099.99",
                    "buy_url": "https://bestbuy.7tiv.net/c/376373/633495/10014?prodsku=6443227&u=http%3A%2F%2Fwww.bestbuy.com%2Fsite%2F-%2F6443227.p%3Fcmp%3DRMX"
                }
            ],
            "256GB 6GB RAM": [
                {
                    "shop_image": "https://fdn.gsmarena.com/imgroot/static/stores/ebay-com2.png",
                    "price": "$ 1,148.99",
                    "buy_url": "https://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=2&toolid=10044&campid=5338659500&customid=gsmarena&lgeo=1&vectorid=229466&item=284606495982"
                },
                {
                    "shop_image": "https://fdn.gsmarena.com/imgroot/static/stores/amazon-com1.png",
                    "price": "$ 1,199.00",
                    "buy_url": "https://www.amazon.com/dp/B09G8Y5SM6?tag=gsmarena093-20&linkCode=osi&th=1&psc=1"
                },
                {
                    "shop_image": "https://fdn.gsmarena.com/imgroot/static/stores/best-buy-1.png",
                    "price": "$ 1,199.99",
                    "buy_url": "https://bestbuy.7tiv.net/c/376373/633495/10014?prodsku=6443233&u=http%3A%2F%2Fwww.bestbuy.com%2Fsite%2F-%2F6443233.p%3Fcmp%3DRMX"
                }
            ],
            "512GB 6GB RAM": [
                {
                    "shop_image": "https://fdn.gsmarena.com/imgroot/static/stores/amazon-com1.png",
                    "price": "$ 1,399.00",
                    "buy_url": "https://www.amazon.com/dp/B09G9J47CQ?tag=gsmarena093-20&linkCode=osi&th=1&psc=1"
                },
                {
                    "shop_image": "https://fdn.gsmarena.com/imgroot/static/stores/ebay-com2.png",
                    "price": "$ 1,399.00",
                    "buy_url": "https://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=2&toolid=10044&campid=5338659500&customid=gsmarena&lgeo=1&vectorid=229466&item=284752225215"
                },
                {
                    "shop_image": "https://fdn.gsmarena.com/imgroot/static/stores/best-buy-1.png",
                    "price": "$ 1,399.99",
                    "buy_url": "https://bestbuy.7tiv.net/c/376373/633495/10014?prodsku=6443343&u=http%3A%2F%2Fwww.bestbuy.com%2Fsite%2F-%2F6443343.p%3Fcmp%3DRMX"
                }
            ]
        },
        "pictures": [
            "https://fdn2.gsmarena.com/vv/pics/apple/apple-iphone-13-pro-max-01.jpg",
            "https://fdn2.gsmarena.com/vv/pics/apple/apple-iphone-13-pro-max-1.jpg",
            "https://fdn2.gsmarena.com/vv/pics/apple/apple-iphone-13-pro-max-5.jpg",
            "https://fdn2.gsmarena.com/vv/pics/apple/apple-iphone-13-pro-max-2.jpg",
            "https://fdn2.gsmarena.com/vv/pics/apple/apple-iphone-13-pro-max-3.jpg",
            "https://fdn2.gsmarena.com/vv/pics/apple/apple-iphone-13-pro-max-4.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_002.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_003.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_004.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_005.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_006.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_007.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_008.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_009.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_010.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_011.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_012.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_013.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_014.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_015.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_016.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_017.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_018.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_019.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_020.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_021.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_022.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_023.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_024.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_025.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_026.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_027.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_028.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_029.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_030.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_031.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_032.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_033.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_034.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_035.jpg",
            "https://fdn.gsmarena.com/imgroot/reviews/21/apple-iphone-13-pro-max/lifestyle/-1024w2/gsmarena_036.jpg"
        ],
        "more_information": {
            "Related Devices": [
                {
                    "device_name": "Samsung Galaxy S22 Ultra 5G",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/samsung-galaxy-s22-ultra-5g.jpg",
                    "key": "samsung_galaxy_s22_ultra_5g-11251"
                },
                {
                    "device_name": "Apple iPhone 13 Pro",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/apple-iphone-13-pro.jpg",
                    "key": "apple_iphone_13_pro-11102"
                },
                {
                    "device_name": "Apple iPhone 12 Pro Max",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/apple-iphone-12-pro-max-.jpg",
                    "key": "apple_iphone_12_pro_max-10237"
                },
                {
                    "device_name": "Apple iPhone 13",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/apple-iphone-13.jpg",
                    "key": "apple_iphone_13-11103"
                },
                {
                    "device_name": "Apple iPhone 11 Pro Max",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/apple-iphone-11-pro.jpg",
                    "key": "apple_iphone_11_pro_max-9846"
                },
                {
                    "device_name": "Xiaomi 12S Ultra",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/xiaomi-12s-ultra.jpg",
                    "key": "xiaomi_12s_ultra-11614"
                }
            ],
            "Popular from Apple": [
                {
                    "device_name": "Apple iPhone 13 Pro Max",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/apple-iphone-13-pro-max.jpg",
                    "key": "apple_iphone_13_pro_max-11089"
                },
                {
                    "device_name": "Apple iPhone XR",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/apple-iphone-xr-new.jpg",
                    "key": "apple_iphone_xr-9320"
                },
                {
                    "device_name": "Apple iPhone X",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/apple-iphone-x.jpg",
                    "key": "apple_iphone_x-8858"
                },
                {
                    "device_name": "Apple iPhone XS Max",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/apple-iphone-xs-max-new1.jpg",
                    "key": "apple_iphone_xs_max-9319"
                },
                {
                    "device_name": "Apple iPhone 13",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/apple-iphone-13.jpg",
                    "key": "apple_iphone_13-11103"
                },
                {
                    "device_name": "Apple iPhone 11",
                    "device_image": "https://fdn2.gsmarena.com/vv/bigpic/apple-iphone-11.jpg",
                    "key": "apple_iphone_11-9848"
                }
            ]
        }
    }
}

Am reusit sa inserez in baza de date key, device_name, device_image, …, comment

		
$client = new Client();	 		
$headers = [
  'Content-Type' => 'application/json'
];
$body = '{
  "route": "device-detail",
  "key": "'.$mobile->key.'"
}';
$request = new Request('POST', 'https://script.google.com/macros/s/AKfycbxNu27V2Y2LuKUIQMK8lX1y0joB6YmG6hUwB1fNeVbgzEh22TcDGrOak03Fk3uBHmz-/exec', $headers, $body);
$res = $client->sendAsync($request)->wait();


$gsm_device = $res->getBody();

$g_device = json_decode($gsm_device);
$device = $g_device->data;

			
$db->query(sprintf("INSERT INTO device (brand_name, brand_key, ..., more_specification) VALUES (%s, %s, ..., %s)", secure($model->brand_name), secure($model->key), ..., secure($device->device_image), secure($device->key), secure($device->more_specification) )) or _error("SQL_ERROR_THROWEN");	

De la data->more_specification lucrurile pentru mine s-au complicat.
Nu stiu cum sa introduc mai departe rezultatele din more_specification. Nu mai sunt valori unice, title si data se tot repeta si nu stiu cum sa fac.

Exista o posibilitate sa introduc tot ce este in more_specification intr-o coloana din baza de date ca continut html, ca un tabel?

Parca mysql suport json

Acel more_specification este un array de obiecte care o sa se repete pt fiecare inregistrare.

Sau il poti salva ca si text si il extragi cum este. Coloanele care se reptea din more_specification pot fi un cap de tabel.


Nu cred ca etse cea mai buna idee, dar poate te ajuta.

1 Like

pt date in care sa faci cautare, query-uri, acolo se preteaza o tabela cu “specificatii”, care sa aiba si camp de id_parinte:

id, id_parent, title, data

cand data e gol, cauti copiii acelei inregistrari.

1 Like

Ideal era ca fiecare titlu de specificație să stea într-un tabel cu posibilitatea de a exista părinte (pentru că văd un tree în specificații).

Apoi, într-un alt tabel ar trebui introduse valorile specificațiilor.

Între tabelele astea două de mai sus ar trebui să existe o relație.

Apoi ar trebui să existe un alt tabel care să facă legătura dintre tabelul care conține valorile specificațiilor și produse.

Dacă alegi să stochezi specificațiile altfel, adică în format json/text, atunci s-ar putea să-ți dea de furcă dacă vei vrea la un moment dat să filtrezi rezultatele căutând în coloana pentru specificații.

De regulă, datele nu se stochează în baza de date ca json/text. Decât dacă ai certitudinea că le vei afișa ca atare.

Nu vreau sa mai fac nimic cu more_specification vreau sa il afisez ca un tabel html

Bun. Atunci păstrezi coloana more_specification și inserezi array-ul în format json, adică:

$db->query(sprintf("INSERT INTO device (brand_name, brand_key, ..., more_specification) VALUES (%s, %s, ..., %s)", secure($model->brand_name), secure($model->key), ..., secure($device->device_image), secure($device->key), secure(json_encode($device->more_specification)) )) or _error("SQL_ERROR_THROWEN");

La afișare, ai nevoie de json_decode și for sau foreach.

PS: Ar trebui să verifici cum sanitizează datele funcția secure, să nu-ți strice json-ul.

Il inserezi asa cum e si ulterior extragi ce te intereseaza. Poate realizezi peste o luna ca aveai nevoie si de informatia care azi ai arunca-o.

MySQL are tipul de date JSON numai ca operatiile de cautare sunt complicate si lente pe acest tip de date. Oricum, structurile de tip JSON pot fi variabile iar ordinea nu este garantata prin urmare nu e recomandat sa le desfaci in coloane specifice bazelor de date SQL. Pentru ce vrei tu sa faci e mult mai bine sa folosesti o baza de date de tip nosql cum ar fi MongoDB care are suport nativ exact pentru stocare si cautare in documente JSON. Totusi, daca MySQL este impus eu as folosi un camp de tip JSON pentru acea structura.

Am gasit aceasta functie :grin:

function jsonToTable ($data)
{
    $table = '
    <table class="json-table" width="100%">
    ';
    foreach ($data as $key => $value) {
        $table .= '
        <tr valign="top">
        ';
        if ( ! is_numeric($key) ) {
            $table .= '
            <td>
                <strong>'. $key .':</strong>
            </td>
            <td>
            ';
        } else {
            $table .= '
            <td colspan="2">
            ';
        }
        if (is_object($value) || is_array($value)) {
            $table .= jsonToTable($value);
        } else {
            $table .= $value;
        }
        $table .= '
            </td>
        </tr>
        ';
    }
    $table .= '
    </table>
    ';
    return $table;
}

$mysql_result = '[{"title":"Network","data":[{"title":"Technology","data":["GSM \/ HSPA \/ LTE"]},{"title":"2G bands","data":["GSM 850 \/ 900 \/ 1800 \/ 1900 - SIM 1 & SIM 2"]},{"title":"3G bands","data":["HSDPA 850 \/ 900 \/ 2100 - International"]},{"title":"4G bands","data":["1, 3, 5, 7, 8, 20, 28, 38, 40, 41 - International"]},{"title":"Speed","data":["HSPA 42.2\/5.76 Mbps, LTE Cat4 150\/50 Mbps"]}]},{"title":"Launch","data":[{"title":"Announced","data":["2021, July 27"]},{"title":"Status","data":["Available. Released 2021, October 12"]}]},{"title":"Body","data":[{"title":"Dimensions","data":["177.7 x 79.1 x 9.9 mm (7.00 x 3.11 x 0.39 in)"]},{"title":"Weight","data":["237 g (8.36 oz)"]},{"title":"SIM","data":["Dual SIM (Nano-SIM, dual stand-by)"]}]},{"title":"Display","data":[{"title":"Type","data":["IPS LCD"]},{"title":"Size","data":["6.82 inches, 112.3 cm2 (~79.9% screen-to-body ratio)"]},{"title":"Resolution","data":["720 x 1600 pixels, 20:9 ratio (~257 ppi density)"]}]},{"title":"Platform","data":[{"title":"OS","data":["Android 11 (Go edition)"]},{"title":"Chipset","data":["Unisoc SC9863A (28nm)"]},{"title":"CPU","data":["Octa-core (4x1.6 GHz Cortex-A55 & 4x1.2 GHz Cortex-A55)"]},{"title":"GPU","data":["IMG8322"]}]},{"title":"Memory","data":[{"title":"Card slot","data":["microSDXC (dedicated slot)"]},{"title":"Internal","data":["32GB 2GB RAM, 32GB 3GB RAM, 64GB 3GB RAM"]}]},{"title":"Main Camera","data":[{"title":"Dual","data":["13 MP, (wide)\n2 MP, (depth)"]},{"title":"Features","data":["LED flash"]},{"title":"Video","data":["1080p@30fps"]}]},{"title":"Selfie camera","data":[{"title":"Single","data":["5 MP"]},{"title":"Video","data":["Unspecified"]}]},{"title":"Sound","data":[{"title":"Loudspeaker","data":["Yes"]},{"title":"3.5mm jack","data":["Yes"]}]},{"title":"Comms","data":[{"title":"WLAN","data":["Wi-Fi 802.11 b\/g\/n, hotspot"]},{"title":"Bluetooth","data":["4.2, A2DP"]},{"title":"GPS","data":["Yes, with A-GPS"]},{"title":"NFC","data":["No"]},{"title":"Radio","data":["FM radio"]},{"title":"USB","data":["microUSB 2.0, USB On-The-Go"]}]},{"title":"Features","data":[{"title":"Sensors","data":["Fingerprint (rear-mounted), accelerometer, proximity"]}]},{"title":"Battery","data":[{"title":"Type","data":["Li-Po 6000 mAh, non-removable"]}]},{"title":"Misc","data":[{"title":"Colors","data":["Green, White, Dark Grey"]},{"title":"Models","data":["TA-1357, TA-1377, TA-1369, TA-1360, TA-1359"]},{"title":"SAR","data":["0.33 W\/kg (head) \u00a0 \u00a0 1.19 W\/kg (body)"]},{"title":"SAR EU","data":["0.41 W\/kg (head) \u00a0 \u00a0 1.29 W\/kg (body)"]},{"title":"Price","data":["$\u2009140.99"]}]}]';
echo jsonToTable(json_decode($mysql_result));


Cum pot ascunde title: si data: ?

Scoti key.
Alea sunt cheile din json.
Vezi pe aici