我正在开发一段自定义脚本(目前还比较混乱)。基本上,它会列出存在于我的数据库中的流信息和链接。同时,脚本会从twitch.tv API获取信息。其中之一是观看者人数。我应该怎么按照观看者数量排序列表,最高的排在第一位?我尝试使用sort函数,但不知道如何在这种情况下使用。
以下是脚本内容:
以下是脚本内容:
// 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>";