Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

another json problem. 1

Status
Not open for further replies.

charlion

Programmer
Jun 30, 2017
3
ZA
hello everyone. im not a professional PHP programmer. but im practicing some skill working with an api( using php to call and display data that is stored in json on my localhost(wampserver).
my codes are these:
<?php
$url = " $get= file_get_contents($url);
$decode= json_decode($get, true);
echo $decode['ico']['live']['name'];
?>


when i run it the error does:
Notice: Undefined index: name in C:\wamp64\www...

please can someone tell me what i have done wrong,or what i have to do. what i wanted is to display the datas in tabular manner.
thank you
 
The ['live'] index is an array of elements. each element then has a ['name'] element inside. But there is no ['name'] index directly under ['live'] so you need to specify which element in the ['live'] array you want the name for.

You would need to do something like: $decode['ico']['live'][x]['name'];

Where "x" is a number between 0 and apparently 277.

If you are unsure of what the structure of the array looks like, its always helpful to print it out entirely in a structured form to be able to see it.

echo "<pre>" . print_r($decode,1) . "</pre>";


----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top