Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从JSON数据类型特定值中从postgres数据库获取行_Php_Mysql_Postgresql_Codeigniter - Fatal编程技术网

Php 从JSON数据类型特定值中从postgres数据库获取行

Php 从JSON数据类型特定值中从postgres数据库获取行,php,mysql,postgresql,codeigniter,Php,Mysql,Postgresql,Codeigniter,您好,我在从Json列提取行时遇到问题。 下面是json数据,如果我想从中提取行,比如从值中提取MH 以下数据位于每行中。所以我需要一个codeigniter查询,如果我查询此列的MH,则需要获取行。 你能帮我解决这个问题吗 下面是JSON数据:[“AP”、“AR”、“AS”、“BR”、“CT”、“GA”、“GJ”、“HR”、“HP”、“JK”、“JH”、“KA”、“KL”、“MP”、“MH”、“MN”、“ML”、“MZ”、“NL”、“OR”、“PB”、“RJ”、“SK”、“TN”、“TG”、“

您好,我在从Json列提取行时遇到问题。
下面是json数据,如果我想从中提取行,比如从值中提取MH

以下数据位于每行中。所以我需要一个codeigniter查询,如果我查询此列的MH,则需要获取行。
你能帮我解决这个问题吗

下面是JSON数据:
[“AP”、“AR”、“AS”、“BR”、“CT”、“GA”、“GJ”、“HR”、“HP”、“JK”、“JH”、“KA”、“KL”、“MP”、“MH”、“MN”、“ML”、“MZ”、“NL”、“OR”、“PB”、“RJ”、“SK”、“TN”、“TG”、“TR”、“UT”、“UP”、“WB”、“AN”、“CH”、“DN”、“DD”、“DL”、“LD”、“PY”]

表结构如下所示。 访问以下网站

拜访

然后从

$this->select('guid, applicability, name, type, description,
service_type, scheme_type, mini_description, tags, benefit');
$this->join('schemes_lang_1', 'schemes_lang_1.scheme_id=scheme_1.id', 'left');
$this->where('lang', $lang);
$this->where('status', $status);
$this->where('scheme_1.pp_enabled', 1);
$this->where('scheme_1.applicability', 'MH');
return $this->findAll();


下面给出的是行查询,您可以将此查询用作参考,并添加所需的任意条件

SELECT
  guid, 
  applicability, 
  name, 
  type, 
  description,
  service_type, 
  scheme_type, 
  mini_description, 
  tags, 
  benefit
FROM scheme_1
LEFT JOIN schemes_lang_1 ON schemes_lang_1.scheme_id=scheme_1.id
WHERE
  (scheme_1.applicability)::jsonb ? 'MH';
还可以通过json键检查条件,如 如果json是这样的

["company":"AP","Detail":"test"]
$this->select('guid, applicability, name, type, description,
service_type, scheme_type, mini_description, tags, benefit');
$this->join('schemes_lang_1', 'schemes_lang_1.scheme_id=scheme_1.id', 'left');
$this->where('lang', $lang);
$this->where('status', $status);
$this->where('scheme_1.pp_enabled', 1);
$this->where('(scheme_1.applicability)::jsonb ? ', 'MH');

return $this->findAll();
使用
(方案1.适用性->“公司”)::jsonbAP'

在Codeignator中,您可以这样做

["company":"AP","Detail":"test"]
$this->select('guid, applicability, name, type, description,
service_type, scheme_type, mini_description, tags, benefit');
$this->join('schemes_lang_1', 'schemes_lang_1.scheme_id=scheme_1.id', 'left');
$this->where('lang', $lang);
$this->where('status', $status);
$this->where('scheme_1.pp_enabled', 1);
$this->where('(scheme_1.applicability)::jsonb ? ', 'MH');

return $this->findAll();

注意:使用循环然后在表字段内逐个搜索记录要快得多,循环搜索可能会将代码的时间和空间复杂度增加1000倍。

这并没有真正利用SQL和postgresql jsonb的优点。也应避免循环