【发布时间】:2014-05-08 08:39:57
【问题描述】:
我正在开发一个自定义脚本(现在,它很脏)。基本上它列出了我数据库中的流信息和链接。同时,它从 twitch.tv API 获取信息。从 API 中检索到的信息之一是观看者的数量。如何按观众数量对列表进行排序,最高优先?我尝试使用排序功能,但我不知道在这种情况下如何使用它。
这是脚本。
// developed by Luigi Robles
$con = mysqli_connect("localhost", "****", "****", '****');
$result = mysqli_query($con,"SELECT * FROM streams");
echo "<table border='1'>
<tr>
<th>Stream name</th>
<th>status</th>
<th>game</th>
<th>viewers</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($row['channel']).'?client_id='.$clientId), true);
if ($json_array['stream'] != NULL) {
echo "<tr>";
echo "<td>" . $json_array['stream']['channel']['display_name'] . "</td>";
echo "<td>" . $json_array['stream']['channel']['status'] . "</td>";
echo "<td>" . $json_array['stream']['channel']['game'] . "</td>";
echo "<td>" . $json_array['stream']['viewers'] . "</td>";
echo "</tr>";
}
}
echo "</table>";
【问题讨论】:
标签: php arrays json api sorting