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 != ""'))  {
    
    $result->execute();
    $result->store_result();
    $result->bind_result($twitchfield);
    while($result->fetch()) {
    echo $twitchfield;
    $data = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/' . $twitchfield),true);
    var_dump($data);
    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 Justin.tv 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]