RapidAPI: php and json code

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 1653 Views - Last Post: 05 April 2019 - 11:30 AM Rate Topic: -----

#16 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,971
  • Joined: 15-January 14

Re: RapidAPI: php and json code

Posted 03 April 2019 - 11:48 AM

Do a print_r on $result to see what it is. If it's false or blank, then print $server_output. You need to figure out what you're getting back and why it's an error. You need to verify the data you're trying to use.
Was This Post Helpful? 0
  • +
  • -

#17 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3814
  • View blog
  • Posts: 13,870
  • Joined: 08-August 08

Re: RapidAPI: php and json code

Posted 04 April 2019 - 04:50 PM

Headers don't belong in the url.
https://www.php.net/...n/book.curl.php
Was This Post Helpful? 0
  • +
  • -

#18 jacob_1988   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 12-August 18

Re: RapidAPI: php and json code

Posted 05 April 2019 - 11:22 AM

I have used the print_r function in my PHP code and the results print to screen (as below), there seems to be a problem with the echo command printing the results?


json file.

print_r($dataForMatches);

Array
(
    [0] => stdClass Object
        (
            [id] => 43458
            [matchTypeId] => 0
            [statisticsProvider] => Opta Sports
            [series] => stdClass Object
                (
                    [id] => 2141
                    [name] => IPL 2018
                    [shortName] => IPL 2018
                    [shieldImageUrl] => https://www.cricket.com.au/-/media/Logos/Series/2016/IPL-new.ashx
                )

            [name] => Match 48
            [status] => COMPLETED
            [venue] => stdClass Object
                (
                    [name] => Holkar Cricket Stadium, Indore
                    [location] => 
                    [latitude] => 
                    [longitude] => 
                    [antisocialPhoneNumber] => 
                )

            [homeTeam] => stdClass Object
                (
                    [isBatting] => 
                    [id] => 63
                    [name] => Kings XI Punjab
                    [shortName] => KXI
                    [logoUrl] => https://www.cricket.com.au/-/media/Logos/Teams/Other/Team-Kings-XI-Punjab.ashx
                    [teamColour] => #d10000
                )

            [awayTeam] => stdClass Object
                (
                    [isBatting] => 1
                    [id] => 57
                    [name] => Royal Challengers Bangalore
                    [shortName] => RCB
                    [logoUrl] => https://www.cricket.com.au/-/media/Logos/Teams/Other/Team-Royal-Challengers-Bangalore.ashx
                    [teamColour] => #ae181d
                )


Was This Post Helpful? 0
  • +
  • -

#19 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,971
  • Joined: 15-January 14

Re: RapidAPI: php and json code

Posted 05 April 2019 - 11:30 AM

You didn't show all of the output, but the array you show does not have things like id. What you show has a single element, and that element has id, matchTypeId, etc.

It is an array of matches, and each match has the information you're looking for. You need to loop through it.

Quote

there seems to be a problem with the echo command printing the results?

Look at the manual page for print_r, you can use the second parameter to tell it whether to print the result or return the result.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2