0

The error I'm getting is

Warning: Variable passed to each() is not an array or object in /home2/xtrapsp/public_html/Admin/index.php on line "while (list(, $val) = each($channel)) { "

However, I am using a direct object within the each() parameters.

$query = "SELECT * FROM Streamers" or die("Error in the consult.." . mysqli_error($link));
$row = mysqli_fetch_array($result);
$channel = $row["name"];
//execute the query. 
$result = mysqli_query($link, $query); 

    while (list(, $val) = each($channel)) {
       $url = "https://api.twitch.tv/kraken/streams/".$val;
       $json = file_get_contents($url);
       $json = json_decode($json);
       $stream =  $json->stream;
             if($stream != null){   
                    $channelAPI = json_decode(file_get_contents('https://api.twitch.tv/kraken/channels/'. $val));
                    $status     = $channelAPI->status;
                    $name       =  $channelAPI->display_name;
                    $gameimg    = "http://static-cdn.jtvnw.net/ttv-boxart/".$channelAPI->game . "-272x380.jpg";
                    $viewers    = $streamsAPI->stream->viewers;
                    $followers  = $channelAPI->followers;
                    $views      = $channelAPI->views;
                    $avatar     = $channelAPI->logo;

                        echo    '<tr><td><a href="/cast.php?caster='.$val.'"/><img src="' . $avatar . '" width="60px"/></a></td>';
                        echo    '<td><a href="#"> <i class="fa fa-circle text-success"></i> Online</a>  </td>';
                        echo    '<td>Game: '. $channelAPI->game.'</tr>';            
            }
        }
        if($stream == null){    
            Echo    'No Dream2Streamers online!';
        }

Would someone mind explaining why it is throwing this error? I am trying to query if the channel inside a mysql database is online and if it is, produce the right data on page.

Thanks

1 Answer 1

2

i think its cause you are fetching the date before running the query , try this

$query = "SELECT * FROM Streamers" or die("Error in the consult.." . mysqli_error($link));
//execute the query. 
$result = mysqli_query($link, $query);

while ($row =  mysqli_fetch_array($result)) {
   $val = $row["name"];
   $url = "https://api.twitch.tv/kraken/streams/".$val;
   $json = file_get_contents($url);
   $json = json_decode($json);
   $stream =  $json->stream;
         if($stream != null){   
                $channelAPI = json_decode(file_get_contents('https://api.twitch.tv/kraken/channels/'. $val));
                $status     = $channelAPI->status;
                $name       =  $channelAPI->display_name;
                $gameimg    = "http://static-cdn.jtvnw.net/ttv-boxart/".$channelAPI->game . "-272x380.jpg";
                $viewers    = $streamsAPI->stream->viewers;
                $followers  = $channelAPI->followers;
                $views      = $channelAPI->views;
                $avatar     = $channelAPI->logo;

                    echo    '<tr><td><a href="/cast.php?caster='.$val.'"/><img src="' . $avatar . '" width="60px"/></a></td>';
                    echo    '<td><a href="#"> <i class="fa fa-circle text-success"></i> Online</a>  </td>';
                    echo    '<td>Game: '. $channelAPI->game.'</tr>';            
        }
    }
    if($stream == null){    
        Echo    'No Dream2Streamers online!';
    }
Sign up to request clarification or add additional context in comments.

3 Comments

That's one problem, but $channel is one value from one row.
Hey guys, thanks for helping. I think I have an inf-loop now. Page won't load past that content and won't stop loading! haha. However, I do understand what @AbraCadaver is saying :)
oops @BradlySpicer my bad , we should fetch array in while condition

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.