我想对 json 数据进行排序,但排序显示错误。这是什么原因?下面是我的数据库表的名称,我在下面给出了页面列名称page_content和 json 数据。我哪里出错了?我是新来的。如果您采取相应行动,请感到高兴。
数据库数据page_content
{
"kind":"video",
"etag":"edtags",
"id":"id",
"statistics":{
"viewCount":"1434348",
}
}
{
"kind":"video",
"etag":"edtags",
"id":"id",
"statistics":{
"viewCount":"16058462",
}
}
{
"kind":"video",
"etag":"edtags",
"id":"id",
"statistics":{
"viewCount":"2176846",
}
}
{
"kind":"video",
"etag":"edtags",
"id":"id",
"statistics":{
"viewCount":"8088410",
}
}
{
"kind":"video",
"etag":"edtags",
"id":"id",
"statistics":{
"viewCount":"9885758",
}
}
{
"kind":"video",
"etag":"edtags",
"id":"id",
"statistics":{
"viewCount":"26795682",
}
}
{
"kind":"video",
"etag":"edtags",
"id":"id",
"statistics":{
"viewCount":"323810",
}
}
{
"kind":"video",
"etag":"edtags",
"id":"id",
"statistics":{
"viewCount":"529588",
}
}
{
"kind":"video",
"etag":"edtags",
"id":"id",
"statistics":{
"viewCount":"6416534",
}
}
索引.php
$query = $db->query('SELECT * FROM pages order by JSON_EXTRACT(page_content,"$.statistics.viewCount") ASC');
$query->execute();
$row = $query->fetchAll(PDO::FETCH_ASSOC);
if ($row ) {
foreach ($row as $value) {
$json = json_decode($value['page_content'], true);
$videoView = $json['statistics']['viewCount'];
echo $videoView;
}
}
打印_r
9885758
8088410
6416534
529588
323810
26795682
2176846
16058462
1434348
函数式编程