0

I have a code for debtor's lustration (executory), but I'm not familiar with the structure of the data. I'm not able to put it record by record in a nice table (even after I read a few threads here). Can you help me with this, please?

My code for fetch json data is:

$urlSearch = 'https://www.ceecr.cz/api/v4/search';
                $apiToken3 = 'token=secret_token';
                $nameSearch = 'name=Michael';
                $birthSearch = 'birth=1901-01-01';
                $personSearch = 'person=F';
                $request_url3 = $urlSearch . '?' . $apiToken3 . '&' . $nameSearch . '&' . $birthSearch . '&' . $personSearch;

                $curl3 = curl_init($request_url3);

                curl_setopt($curl3, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl3, CURLOPT_HTTPHEADER, [
                    'X-RapidAPI-Host: ceecr.cz',
                    'X-RapidAPI-Key: ae8wie9Toez0',
                    'Content-Type: application/json'
                ]);

                echo $response3 = curl_exec($curl3);
                curl_close($curl3);

                $vysledky =  json_decode($response3, true);

and now I get this json response

{"status":200,"data":[{"subjects":[{"subject_id":505896577,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"018EX5581\/19","cause_id":"Exk6w3Q","datetime_zalozeni":"2020-12-01","datetime_upravy":"2020-12-01","date_vydano":"2019-10-10","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2019-10-10T00:00:00+02:00"},{"subjects":[{"subject_id":505877637,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"018EX6655\/16","cause_id":"xJWLRz9","datetime_zalozeni":"2020-12-01","datetime_upravy":"2020-12-01","date_vydano":"2016-07-18","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2016-07-18T00:00:00+02:00"},{"subjects":[{"subject_id":505541695,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"203EX52157\/12","cause_id":"y4oWDa3","datetime_zalozeni":"2020-10-15","datetime_upravy":"2020-10-15","date_vydano":"2012-11-02","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2012-11-02T00:00:00+01:00"},{"subjects":[{"subject_id":503487104,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"106EX9853\/12","cause_id":"6qZn7e4","datetime_zalozeni":"2020-09-07","datetime_upravy":"2020-09-07","date_vydano":"2013-01-02","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2013-01-02T00:00:00+01:00"},{"subjects":[{"subject_id":503206676,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"220EX14857\/12","cause_id":"XD9ePEr","datetime_zalozeni":"2020-09-06","datetime_upravy":"2020-09-06","date_vydano":"2012-12-05","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2012-12-05T00:00:00+01:00"},{"subjects":[{"subject_id":502979099,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"067EX403926\/11","cause_id":"nX4o9Lg","datetime_zalozeni":"2020-09-05","datetime_upravy":"2020-09-05","date_vydano":"2011-11-30","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2011-11-30T00:00:00+01:00"},{"subjects":[{"subject_id":502978222,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"067EX403261\/11","cause_id":"Go2Kz2p","datetime_zalozeni":"2020-09-05","datetime_upravy":"2020-09-05","date_vydano":"2012-09-26","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2012-09-26T00:00:00+02:00"},{"subjects":[{"subject_id":502975505,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"067EX401066\/11","cause_id":"OgOeREO","datetime_zalozeni":"2020-09-05","datetime_upravy":"2020-09-05","date_vydano":"2013-04-23","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2013-04-23T00:00:00+02:00"},{"subjects":[{"subject_id":501985823,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"195EX879\/19","cause_id":"1x4JmQD","datetime_zalozeni":"2020-07-16","datetime_upravy":"2020-07-16","date_vydano":"2019-06-25","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2019-06-25T00:00:00+02:00"},{"subjects":[{"subject_id":501267412,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"070EX921\/19","cause_id":"GoGXjyw","datetime_zalozeni":"2020-07-02","datetime_upravy":"2020-07-02","date_vydano":"2019-06-18","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2019-06-18T00:00:00+02:00"},{"subjects":[{"subject_id":501158391,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"017EX1279\/14","cause_id":"0nJB0Dk","datetime_zalozeni":"2020-07-01","datetime_upravy":"2020-07-01","date_vydano":"2014-06-23","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2014-06-23T00:00:00+02:00"},{"subjects":[{"subject_id":500292883,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Ji\u0159\u00edho n\u00e1m\u011bst\u00ed 20\/1, 290 01 Pod\u011bbrady","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"099EX2526\/19","cause_id":"K4gEm4p","datetime_zalozeni":"2019-10-24","datetime_upravy":"2019-10-29","date_vydano":"2019-08-07","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2019-08-07T00:00:00+02:00"},{"subjects":[{"subject_id":500990582,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":2,"ex_cislo":"070EX4010\/12","cause_id":"b57Rm5x","datetime_zalozeni":"2016-01-08","datetime_upravy":"2016-01-08","date_vydano":"2012-09-05","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2012-09-05T00:00:00+02:00"},{"subjects":[{"subject_id":91226235,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"023EX362\/14","cause_id":"ROW4Ky","datetime_zalozeni":"2014-03-18","datetime_upravy":"2014-09-24","date_vydano":"2014-03-31","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2014-03-31T00:00:00+02:00"},{"subjects":[{"subject_id":51215496,"typ_osoby":"F","jmeno":"Michael","datum_narozeni":"1901-01-01","ico":null,"ic":null,"adresa":"Prague","adm":18327991,"identification":{"type":"rc","hash":"LwKvzy4"}}],"subject_count":1,"ex_cislo":"081EX31382\/12","cause_id":"3e2qz5","datetime_zalozeni":"2013-03-18","datetime_upravy":"2013-03-18","date_vydano":"2012-10-22","posledni_uprava":"Pravomocn\u00e1 exekuce","datum_soudniho_narizeni":"2012-10-22T00:00:00+02:00"}],"dataSource":"regular","info":{"search":{"type":"name|birthdate","query":"Michael|1901-01-01"},"zbyva_dotazu":{"placenych":11,"free":null},"zbyvajici_kredit":660,"cena":{"zaplaceno":"60 CZK","kredit":660},"debug":{"found":15}}}

For better readability, I recommend http://array.include-once.org/

I can't list each record separately, the result should look something like this: enter image description here

I beg you very much, save my life and my nerves. Thank you very much

4
  • What doesn't work? Where's the problem? Creating HTML tables? foreaching the data? What have you tried so far? Commented Oct 31, 2021 at 13:13
  • btw, It doesn't have to list all the values for me, but just subjects.subject_id, subjects.typ_osoby, subjects.name, I can add the rest of the data myself according to the enclosed code Commented Oct 31, 2021 at 13:18
  • @brombeer both :) I try this for example pastebin.com/YCqJ19RV Commented Oct 31, 2021 at 13:26
  • @brombeer It's hard for me and I would need specific code for my situation to understand it. My mistake was learning the copy and paste style :( Commented Oct 31, 2021 at 13:33

2 Answers 2

1

It should be as easy as below

$data = empty($vysledky['data']) ? [] : $vysledky['data'];
foreach ($data as $subject_collection) {
   if (empty($subject_collection['subjects'])) continue;
   foreach ($subject_collection['subjects'] as $subject) {
       // you can now pull out data such as subject_id etc.
       var_dump($subject);
   }
}

See repl.it for reference

Sign up to request clarification or add additional context in comments.

4 Comments

Oh, you are my god :) I am finish, thank you very very much ! :)
You're welcome, glad I could help :)
@MichaelGrznár If this answer solved your problem, please mark it as accepted
@brombeer done. I forgot, I am sorry :)
1

If I got your question right, I think below code should work -

$data = json_decode($vysledky->data, true);
foreach ($data as $key => $value) {
   $subject_id = $value['subjects'][0]['subject_id]; //as subject_id in within another array
   $ex_cislo = $value['subjects']['ex_cislo']; //ex_cislo is attribute of $value array
}

3 Comments

I've tried something similar, but I don't know how to get those values, like "subject_id", "ex_number", "datetime_zalozeni" etc. Each record on one row in the table. Would you please add yours // iterate every row as table column
@MichaelGrznár - I have modified the code, you can check
Thank you very much for help :) it will help me in the future, but i needed this link

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.