Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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 仅选择sql中与codeigniter匹配的值_Php_Jquery_Mysql_Codeigniter - Fatal编程技术网

Php 仅选择sql中与codeigniter匹配的值

Php 仅选择sql中与codeigniter匹配的值,php,jquery,mysql,codeigniter,Php,Jquery,Mysql,Codeigniter,我在mysql中还有6个表,每个字段都有一个唯一的字段“works\u id”,我在这些表中输入数据。我只想匹配它显示的值,但它需要16行。假设在worker name字段中,它显示两个名称,重复8次,但我只需要两个名称一次。可能需要两排。但这怎么可能呢。我的表格显示: Ser Works ID Date Of Works Infrastructure Name of System Type of Works Vendor Name Worker Name 1

我在mysql中还有6个表,每个字段都有一个唯一的字段“works\u id”,我在这些表中输入数据。我只想匹配它显示的值,但它需要16行。假设在worker name字段中,它显示两个名称,重复8次,但我只需要两个名称一次。可能需要两排。但这怎么可能呢。我的表格显示:

Ser Works ID Date Of Works Infrastructure Name of System Type of Works Vendor Name Worker Name 1 1016 2017-03-12 Server JoinBDApps Trobleshooting Vintage IT Md Rajaon 2 1016 2017-03-12 Server JoinBDApps Software Upgrade Vintage IT Md Rajaon 3 1016 2017-03-12 Network JoinBDApps Trobleshooting Vintage IT Md Rajaon 4 1016 2017-03-12 Network JoinBDApps Software Upgrade Vintage IT Md Rajaon 5 1016 2017-03-12 Server CMH Trobleshooting Vintage IT Md Rajaon 6 1016 2017-03-12 Server CMH Software Upgrade Vintage IT Md Rajaon 7 1016 2017-03-12 Network CMH Trobleshooting Vintage IT Md Rajaon 8 1016 2017-03-12 Network CMH Software Upgrade Vintage IT Md Rajaon 9 1016 2017-03-12 Server JoinBDApps Trobleshooting GP IT Md Forkan 10 1016 2017-03-12 Server JoinBDApps Software Upgrade GP IT Md Forkan 11 1016 2017-03-12 Network JoinBDApps Trobleshooting GP IT Md Forkan 12 1016 2017-03-12 Network JoinBDApps Software Upgrade GP IT Md Forkan 13 1016 2017-03-12 Server CMH Trobleshooting GP IT Md Forkan 14 1016 2017-03-12 Server CMH Software Upgrade GP IT Md Forkan 15 1016 2017-03-12 Network CMH Trobleshooting GP IT Md Forkan 16 1016 2017-03-12 Network CMH Software Upgrade GP IT Md Forkan Ser Works ID工程日期基础设施名称系统类型工程供应商名称工人名称 1 1016 2017-03-12服务器连接应用程序Trobleshooting Vintage IT Md Rajaon 2 1016 2017-03-12服务器JoinBDApps软件升级Vintage IT Md Rajaon 3 1016 2017-03-12网络联合应用程序Trobleshooting Vintage IT Md Rajaon 4 1016 2017-03-12网络联合应用软件升级Vintage IT Md Rajaon 5 1016 2017-03-12服务器CMH Trobleshooting Vintage IT Md Rajaon 6 1016 2017-03-12服务器CMH软件升级Vintage IT Md Rajaon 7 1016 2017-03-12网络CMH Trobleshoting Vintage IT Md Rajaon 8 1016 2017-03-12网络CMH软件升级Vintage IT Md Rajaon 9 1016 2017-03-12服务器连接应用程序Trobleshooting GP IT Md Forkan 10 1016 2017-03-12服务器连接应用软件升级GP IT Md Forkan 11 1016 2017-03-12网络连接应用程序Trobleshooting GP IT Md Forkan 12 1016 2017-03-12网络连接应用软件升级GP IT Md Forkan 13 1016 2017-03-12服务器CMH Trobleshooting GP IT Md Forkan 14 1016 2017-03-12服务器CMH软件升级GP IT Md Forkan 15 1016 2017-03-12网络CMH Trobleshooting GP IT Md Forkan 16 1016 2017-03-12网络CMH软件升级GP IT Md Forkan 但我想:

Ser Works ID Date Of Works Infrastructure Name of System Type of Works Vendor Name Worker Name 1 1016 2017-03-12 Server JoinBDApps Trobleshooting Vintage IT Md Rajaon Network CMH Software Upgrade GP IT Md Forkan Ser Works ID工程日期基础设施名称系统类型工程供应商名称工人名称 1 1016 2017-03-12服务器连接应用程序Trobleshooting Vintage IT Md Rajaon 网络CMH软件升级GP IT Md Forkan 我的Codeigniter型号是:

$this->db->select('trxn_tbl.works_id, trxn_tbl.works_date, infrashtructure_txn_info.infrashtructure_name, apps_txn_tbl.apps_name, works_type_txn_tbl.works_type, workers_tbl.vendor_id, workers_tbl.name'); $this->db->from('infrashtructure_txn_info'); $this->db->join('workers_tbl', 'trxn_tbl.works_id = workers_tbl.works_id'); $this->db->join('works_type_txn_tbl', 'trxn_tbl.works_id = works_type_txn_tbl.works_id'); $this->db->join('infrashtructure_txn_info', 'trxn_tbl.works_id = infrashtructure_txn_info.works_id'); $this->db->join('apps_txn_tbl', 'trxn_tbl.works_id = apps_txn_tbl.works_id'); $query = $this->db->get(); return $query->result(); $this->db->select('trxn_tbl.works_id,trxn_tbl.works_date,Infrastructure_txn_info.Infrastructure_name,apps_txn_tbl.apps_name,works_type_txn_tbl.works_type,workers_tbl.vendor_id,workers_tbl.name'); $this->db->from(‘基础设施信息’); $this->db->join('workers\u tbl','trxn\u tbl.works\u id=workers\u tbl.works\u id'); $this->db->join('works\u type\u txn\u tbl','trxn\u tbl.works\u id=works\u type\u txn\u tbl.works\u id'); $this->db->join('infrashstructure\u txn\u info','trxn\u tbl.works\u id=infrashstructure\u txn\u info.works\u id'); $this->db->join('apps\u txn\u tbl','trxn\u tbl.works\u id=apps\u txn\u tbl.works\u id'); $query=$this->db->get(); 返回$query->result(); 请任何人帮助我…

distinct()
放在代码顶部,如下所示:

$this->db->distinct();
$this->db->select('trxn_tbl.works_id, trxn_tbl.works_date, infrashtructure_txn_info.infrashtructure_name, apps_txn_tbl.apps_name, works_type_txn_tbl.works_type, workers_tbl.vendor_id, workers_tbl.name');
...rest of your code...

这有帮助吗?

您应该使用GROUP BY来聚合行:

$this->db->group_by(array('trxn_tbl.works_id', 'infrashtructure_txn_info.infrashtructure_name')); 
如果这样做有效,请尝试:

$this->db->select('trxn_tbl.works_id, trxn_tbl.works_date, infrashtructure_txn_info.infrashtructure_name, apps_txn_tbl.apps_name, works_type_txn_tbl.works_type, workers_tbl.vendor_id, workers_tbl.name');
$this->db->from('infrashtructure_txn_info');
$this->db->join('workers_tbl', 'trxn_tbl.works_id = workers_tbl.works_id');
$this->db->join('works_type_txn_tbl', 'trxn_tbl.works_id = works_type_txn_tbl.works_id');
$this->db->join('infrashtructure_txn_info', 'trxn_tbl.works_id = infrashtructure_txn_info.works_id');
$this->db->join('apps_txn_tbl', 'trxn_tbl.works_id = apps_txn_tbl.works_id');

$this->db->group_by(array('trxn_tbl.works_id', 'infrashtructure_txn_info.infrashtructure_name'));

$query = $this->db->get();

return $query->result();

编辑:如果您通过相关错误获得任何分组,请尝试根据所选内容中的所有命名列进行分组。另一种选择是尝试对GROUP_by子句中未包含的所有列使用
GROUP_CONCAT
。例如:
GROUP_CONCAT(workers_tbl.name分隔符“,”)作为workers_tbl.name

添加
$this->db->GROUP_by('name_of_column')
$this->db->distinct()
Now?之后显示……选择列表的表达式#1不在GROUP BY子句中,并且包含未聚合的列“dcapp_db.trxn_tbl.works_id”,该列在功能上不依赖GROUP BY子句中的列;这与sql\u mode=only\u full\u group\u不兼容。错误似乎与此线程中的错误相同