Php 将mysql查询传递到while循环
我得到的错误是 警告:传递给each()的变量不是/home2/xtrapsp/public_html/Admin/index.php中的数组或对象,而(list(,$val)=each($channel)){ " 但是,我在each()参数中使用了直接对象Php 将mysql查询传递到while循环,php,mysql,Php,Mysql,我得到的错误是 警告:传递给each()的变量不是/home2/xtrapsp/public_html/Admin/index.php中的数组或对象,而(list(,$val)=each($channel)){ " 但是,我在each()参数中使用了直接对象 $query = "SELECT * FROM Streamers" or die("Error in the consult.." . mysqli_error($link)); $row = mysqli_fetch_array($re
$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!';
}
$query=“SELECT*FROM streams”或die(“咨询中出错”)。mysqli_Error($link));
$row=mysqli\u fetch\u数组($result);
$channel=$row[“name”];
//执行查询。
$result=mysqli\u查询($link,$query);
while(列表(,$val)=每个($channel)){
$url=”https://api.twitch.tv/kraken/streams/“$val;
$json=文件获取内容($url);
$json=json_decode($json);
$stream=$json->stream;
如果($stream!=null){
$channelAPI=json\u解码(文件\u获取\u内容('https://api.twitch.tv/kraken/channels/“.$val”);
$status=$channelAPI->status;
$name=$channelAPI->display\u 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“游戏:”.$channelAPI->Game.”;
}
}
如果($stream==null){
Echo“没有Dream2Streamers在线!”;
}
有人能解释一下为什么会抛出这个错误吗?我试图查询mysql数据库中的通道是否在线,如果在线,在页面上生成正确的数据
谢谢我想这是因为您在运行查询之前获取了日期,请尝试以下操作
$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!';
}
$query=“SELECT*FROM streams”或die(“咨询中出错”)。mysqli_Error($link));
//执行查询。
$result=mysqli\u查询($link,$query);
while($row=mysqli\u fetch\u数组($result)){
$val=$row[“name”];
$url=”https://api.twitch.tv/kraken/streams/“$val;
$json=文件获取内容($url);
$json=json_decode($json);
$stream=$json->stream;
如果($stream!=null){
$channelAPI=json\u解码(文件\u获取\u内容('https://api.twitch.tv/kraken/channels/“.$val”);
$status=$channelAPI->status;
$name=$channelAPI->display\u 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“游戏:”.$channelAPI->Game.”;
}
}
如果($stream==null){
Echo“没有Dream2Streamers在线!”;
}
这是一个问题,但是,$channel
是一行中的一个值。嘿,伙计们,谢谢你们的帮助。我想我现在有一个inf循环。页面不会加载超过那个内容,也不会停止加载!哈哈。不过,我确实理解@Abracadver的意思:)oops@BradlySpicer我的错,我们应该在while条件下获取数组