PHP Channel info issues

So i’ve read a few threads on here about grabbing channel data via PHP and JSON, i’ve tried numerous differen’t methods found on these forums and other sites which all result in the same issues. Maybe someone could chime in? Here is my code.

    if ($result = $con->prepare('SELECT field_v
    FROM user_field_value
    WHERE field_id = "twitch"
    AND field_value != ""'))  {
    while($result->fetch()) {
    echo $twitchfield;
    $data = json_decode(file_get_contents('' . $twitchfield),true);
    echo $data->stream->channel->display_name;
    echo $data->stream->viewers;    

So the issue I’m having is storing display_name and viewers into a variable, so to test I just tried echoing them.

I get Notice: Trying to get property of non-object in …

However the vardump comes out fine. I’ve also tried $data[0]->stream->channel->display_name with no luck as well.

What am i doing wrong? Basically I’ve been trying to redo this script since the api was taken down, but not having a fun time yet.

iirc that should do the trick

echo $data['stream']['channel']['display_name'];
echo $data['stream']['viewers'];

Edit: also see Twitch API: Trying To Return No of Viewers [PHP]