Close

Results 1 to 3 of 3
  1. #1
    DF Member Tennisball's Avatar
    Join Date
    Nov 2000
    Location
    England
    Posts
    41
    Thanks
    1
    Thanked:        3
    Karma Level
    287

    Default A little PHP help required

    Im not very good with PHP but I decided to try and create a small script that receives a JSON file from a url. I want to split up this data into a simple TV schedule for the current day. I just cant figure out how to select the info I require from the array. Heres my current code, like I said my PHP knowledge is limited, but the task isnt actually that difficult, or so I thought.

    The script should output something like

    Showname - Season Number - Episode Number - Airtime

    I havnt added all the pieces I need to my code yet,, but I cant even get the Episode and Season data. Any help would be massively appreciated.

    Code:
    <?php
    $today = date("Y-m-d");
    $url = "http://api.tvmaze.com/schedule?date=" . $today;
    $json = file_get_contents($url);
    $data = json_decode($json,true);
    $last = count($data) - 1; // might need later
    
    
    foreach ($data as $kkey => $item ) {
            $season = $kkey['season'];
            $ep = $kkey['number'];
            foreach ($kkey['show'] as $key => $value) {
                    $showname = $key['name'];
                    print "Schedule For " . $today . "\r\n";
                    print $showname . " - " . $season . " - " . $ep . "\r\n";
                    }
            }
    
    
    //print"<pre>";
    //print_r($data);
    //print "</pre>";
    ?>
    The commented part at the bottom if uncommented will just print the $data array so you can see the structure of it.

  2. #2
    DF VIP Member Bald Bouncer's Avatar
    Join Date
    Jun 2001
    Location
    UK
    Posts
    9,770
    Thanks
    4,161
    Thanked:        5,595
    Karma Level
    1131

    Default Re: A little PHP help required

    Code:
    <?php $today = date("Y-m-d");
    $url = "http://api.tvmaze.com/schedule?date=" . $today;
    $json = file_get_contents($url);
    $data = json_decode($json,true);
    $last = count($data) - 1; // might need later
    foreach ($data as $kkey ) {
    $season = $kkey['season'];
    $ep = $kkey['number'];
    $showname = $kkey['show']['name'];
    $episodename = $kkey['name'];
    print "Schedule For " . $today . "\r\n";
    print $showname . " - " . $season . " - " . $ep . " - " . $episodename."\r\n<br>";
    print 'Show Summary - '.$kkey['show']['summary'].'<br>';
    print 'Episode Summary - '.$kkey['summary'].'<br>';
    }
    ?>
    Last edited by Bald Bouncer; 14th November 2015 at 03:46 AM.

    Thanks to Bald Bouncer

    Tennisball (14th November 2015)  


  3. #3
    DF Member Tennisball's Avatar
    Join Date
    Nov 2000
    Location
    England
    Posts
    41
    Thanks
    1
    Thanked:        3
    Karma Level
    287

    Default Re: A little PHP help required

    Damn, I was way overthinking it, im sure i had tried the ['key']['item'] thing before, maybe my foreach was wrong.

    Big thanks Bald Bouncer. I owe you a pint.

Similar Threads

  1. Telepui codes required ?
    By DeltamdX in forum Digital Satellite TV
    Replies: 1
    Last Post: 2nd October 2002, 12:29 AM
  2. Me55i@h-X required
    By BFG in forum Microsoft Consoles
    Replies: 4
    Last Post: 28th September 2002, 02:20 AM
  3. IBM T23 – CD-R/RW – Front Panel required
    By afrokiwi in forum PC Hardware
    Replies: 0
    Last Post: 17th September 2002, 06:53 PM
  4. Problem: Help required (tv issue)
    By brumbino in forum Digital Satellite TV
    Replies: 0
    Last Post: 17th September 2002, 01:51 PM

Social Networking Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •