第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

PHP mysql 按鍵對(duì) JSON 數(shù)據(jù)進(jìn)行排序

PHP mysql 按鍵對(duì) JSON 數(shù)據(jù)進(jìn)行排序

PHP
叮當(dāng)貓咪 2023-08-19 16:24:12
我想對(duì) json 數(shù)據(jù)進(jìn)行排序,但排序顯示錯(cuò)誤。這是什么原因?下面是我的數(shù)據(jù)庫(kù)表的名稱,我在下面給出了頁(yè)面列名稱page_content和 json 數(shù)據(jù)。我哪里出錯(cuò)了?我是新來(lái)的。如果您采取相應(yīng)行動(dòng),請(qǐng)感到高興。數(shù)據(jù)庫(kù)數(shù)據(jù)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;    }}打印_r988575880884106416534529588323810267956822176846160584621434348
查看完整描述

1 回答

?
函數(shù)式編程

TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個(gè)贊

您需要取消引用 json 值,并將其轉(zhuǎn)換為數(shù)字,以便可以使用它進(jìn)行正確的排序。您可以同時(shí)執(zhí)行這兩項(xiàng)操作,如下所示:

order by page_content ->> '$.statistics.viewCount' + 0

如果您的 MySQL 版本不支持運(yùn)算符->>,則:

order by json_extract(page_content, '$.statistics.viewCount')) + 0

DB Fiddle 上的演示- 兩個(gè)查詢都會(huì)產(chǎn)生:

| page_content                                                                             |

| :--------------------------------------------------------------------------------------- |

| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "323810"}}   |

| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "529588"}}   |

| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "1434348"}}  |

| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "2176846"}}  |

| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "6416534"}}  |

| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "8088410"}}  |

| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "9885758"}}  |

| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "16058462"}} |

| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "26795682"}} |



查看完整回答
反對(duì) 回復(fù) 2023-08-19
  • 1 回答
  • 0 關(guān)注
  • 194 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)