0

I have json file that contains of 50 lines of similar

"results":[{"score":0,"team_id":126266},{"score":0,"team_id":125798}].

I need to insert this to database, but I keep getting errors:

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

Here's the code:

$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')";

1 Answer 1

1

You can access as below

$pirmo_oponento_rezultatas = $row['results'][0]['score']; 
$antro_oponento_rezultatas = $row['results'][1]['score'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.