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
    216

    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,729
    Thanks
    4,127
    Thanked:        5,554
    Karma Level
    1253

    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.

    [Only registered and activated users can see links. ]

    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
    216

    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. VB help required please
    By drdude in forum Programming
    Replies: 1
    Last Post: 19th July 2007, 01:57 PM
  2. Help required
    By terrysmr2 in forum Tattoos, Body Art & Piercings
    Replies: 5
    Last Post: 21st April 2006, 04:45 PM
  3. help required
    By tigger3 in forum The Dog and Duck
    Replies: 2
    Last Post: 29th September 2005, 05:06 PM
  4. NEw PDA required
    By NEVETS in forum Microsoft Windows XP & Vista
    Replies: 7
    Last Post: 3rd February 2004, 04:07 PM
  5. help required
    By tiggerbiker in forum System Security
    Replies: 2
    Last Post: 10th February 2003, 06:02 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
  •