L
L
lancerok2018-05-06 12:34:22
PHP
lancerok, 2018-05-06 12:34:22

php + json how to get all id's?

Hello, please help me to implement.
$url = file_get_contents(' https://newvideo.tv/api/category-list?api_key=
[your_api_key]&cat=film');
$decode_url = json_decode($url, true);
foreach($decode_url['data'] as $id){
echo $id['kinopoisk_id'] ;
}
The value of kinopoisk_id is about 9k.
kinopoisk_id is output as a string.
5aeecda2e5cdc754717540.jpeg
How to substitute each id and display info by id ?
$url2 = file_get_contents (' https://newvideo.tv/api/videos?api_key=
[your_api_key]&kinopoisk_id='.$id['kinopoisk_id']);
$decode_url2 = json_decode($url2, true); ';
foreach($decode_url2['data'] as $full_info){
echo $full_info['title_en'] ;
echo $full_info['year'] ; echo '';
echo $full_info['poster'] ; echo '';
}
Put on the right path. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Merzley, 2018-05-06
@lancerok

Try like this:

$url = file_get_contents ('https://newvideo.tv/api/category-list?api_key=[your_api_key]&cat=film');
$decode_url = json_decode($url, true);

foreach($decode_url['data'] as $id){
    $currentId = $id['kinopoisk_id'] ;

    $url2 = file_get_contents ('https://newvideo.tv/api/videos?api_key=[your_api_key]&kinopoisk_id='.$currentId);
    $decode_url2 = json_decode($url2, true);

    foreach($decode_url2['data'] as $full_info){
        echo $full_info['title_ru']; echo '<br>';
        echo $full_info['year']; echo '<br>';
        echo $full_info['poster']; echo '<br>';
        echo '<hr>';
    }
}

UPD
The only thing is that 9k requests for additional information can take quite a long time. This option is not suitable for generating pages on the fly.
UPD2
In the second request, I forgot to change $id['kinopoisk_id'] to $currentId

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question