0

I have this json like :

{
data: [
{
_id: 6,
Logo: "http://s3-eu-west-1.amazonaws.com/korabia-eg/images/Logos/Leagues/6.png",
matches: [
{
matchId: 1393036,
competitionId: 6,
teamAId: 18299,
teamALogo: "http://www.datasportsgroup.com/images/clubs/50x50/18299.png",
teamBId: 733,
teamBLogo: "http://www.datasportsgroup.com/images/clubs/50x50/733.png",
scoreA: 2,
scoreB: 2,
status: "Played",
timing: "2019-02-15T17:00:00Z",
}
],
}
],
}

and i need way to add this data to table in SQL by using foreach,

How can do it?

  • 3
    Welcome to Stack Overflow. It sounds like you have two separate questions here, both of which have been answered extensively on SO. See: [Parsing JSON with PHP](https://stackoverflow.com/questions/4343596/how-can-i-parse-a-json-file-with-php), [Insert into database with foreach](https://stackoverflow.com/questions/46492194/php-foreach-loop-sql-insert). There are tons more examples here and extensive documentation at http://php.net/manual/. Do some research, try some things, and come back when you have a specific coding problem with a [mcve] – tshimkus Feb 16 '19 at 14:32
  • 1
    Possible duplicate of [Parsing JSON with PHP](https://stackoverflow.com/questions/6964403/parsing-json-with-php) – Nino Filiu Feb 16 '19 at 15:43

1 Answers1

0
    <?php 
    $str=file_get_contents("https://www.so3ody.com/api/get_matches_widget?compId=0&dateFrom=2019/2/15&dateTo=2019/2/16&teamId=0&isWeek=true&roundId=0&week=0&seassonId=0");
$ar=json_decode($str,true);// json to array parsing
$data_ar=$ar['data'];//array
//print_r($data_ar);
foreach($data_ar as $key=>$val)
{
    echo $_id=$val["_id"]; // fetchi _id
    echo "<br>";
    echo $_id=$val["Logo"];// fetching Logo
    echo "<br>";


    $matches_array=$val["matches"];//match array
    foreach($matches_array as $key1=>$value1)
    {
        echo $value1["matchId"];
        echo $value1["competitionId"];

    }

}
    ?>

enter image description here

Harshit Sethi
  • 559
  • 1
  • 5
  • 22