我得到的错误是
警告:传递给each()的变量不是/home2/xtrapsp/public_html/Admin/index.php中的数组或对象“while(list(,$ val)= each($ channel)){ “
但是,我在each()参数中使用直接对象。
$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!';
}
有人会介意解释为什么会抛出这个错误吗?我试图查询mysql数据库中的通道是否在线,如果是,则在页面上生成正确的数据。
由于
答案 0 :(得分:2)
我认为原因是你在运行查询之前获取日期,试试这个
$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!';
}