wordpress元值(序列化)过滤器

zwghvu4y  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(224)

我有一个元密钥 _student_registration_data 存储在wordpress数据库中,元值作为序列化数组,如下所示:

a:9:{s:4:"name";s:20:"John Doe";s:11:"father_name";s:10:"Arnold";s:4:"cnic";s:13:"5540545612812";s:12:"home_address";s:9:"Scheme-33";s:16:"telephone_number";s:12:"923332654324";s:15:"registration_id";s:6:"08CS68";s:10:"program_id";s:1:"1";s:9:"cohort_id";s:1:"6";s:10:"section_id";s:1:"7";}

现在我想要一个mysql查询或者一些内置的wordpress函数,借助它我可以过滤usermeta行 registration_id 等于 08CS68 .
谢谢。

wpx232ag

wpx232ag1#

尼克的回答是关键,但没有解决我的问题。实际效果如下:

SELECT * FROM (SELECT * FROM `cn_usermeta` WHERE meta_key = '_student_registration_data') as META WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(META.meta_value, 'registration_id', -1), ';', 2), ':', -1) = '"08CS68"'

特别感谢尼克:)

ogsagwnx

ogsagwnx2#

你可以提取 registration_id 从字符串中使用 SUBSTRING_INDEX :

SELECT *
FROM yourtable
WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(_student_registration_data,
                    'registration_id', -1), ';', 2), ':', -1) = '"08CS68"'

相关问题