gpt4 book ai didi

php - 向数据库插入json数据时如何访问数组中的数组?

转载 作者:行者123 更新时间:2023-11-29 09:28:16 26 4
gpt4 key购买 nike

我有 json 文件,其中包含 50 行类似内容

"结果":[{"score":0,"team_id":126266},{"score":0,"team_id":125798}]

我需要将其插入数据库,但我不断收到错误:

Notice: Undefined index: results[0]:score[0] in D:\xampp\htdocs\json\index.php on line 26

Notice: Undefined index: results[1]:score[0] in D:\xampp\htdocs\json\index.php on line 27

Notice: Undefined index: results[0]:team_id[0] in D:\xampp\htdocs\json\index.php on line 32

Notice: Undefined index: results[1]:team_id[0] in D:\xampp\htdocs\json\index.php on line 33

代码如下:

$pirmo_oponento_rezultatas = $row['results[0]:score[0]'];
$antro_oponento_rezultatas = $row['results[1]:score[0]'];
$fk_Komandosid_Komandos = $row['results[0]:team_id[0]'];
$fk_Komandosid_Komandos1 = $row['results[1]:team_id[0]'];

$sql="INSERT INTO rungtynes (pirmo_oponento_rezultatas,antro_oponento_rezultatas,fk_Komandosid_Komandos,
fk_Komandosid_Komandos1) VALUES ('$pirmo_oponento_rezultatas','$antro_oponento_rezultatas',
'$fk_Komandosid_Komandos','$fk_Komandosid_Komandos1')";

最佳答案

您可以通过以下方式访问

$pirmo_oponento_rezultatas = $row['results'][0]['score']; 
$antro_oponento_rezultatas = $row['results'][1]['score'];

关于php - 向数据库插入json数据时如何访问数组中的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59224717/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com