首页 > 解决方案 > 如何在codeigniter中计算两个表上的子字符串

问题描述

我有两张桌子

table1 id|name|next_field

table2 id|id_of_table1|whatelse

我执行 msql 查询以获取 table1 的所有条目以及 table2 中具有 table2.id_of_table1 = table1.id 的条目数

这是我的查询 - 它工作正常。

$select =array('table1.*', 'COUNT(table2.id) AS `my_count_result`',);
            $this->db->select($select);
            if($id!=false){ $this->db->where('id',$id);  }
            $this->db->from('table1 as t1');
            $this->db->join('table2 as t2', 't1.id = t2.id_of_table1');
            return $this->db->get()->result_array();

现在我有另一个字段,其中包含逗号分隔的数据 table1.next_field = info1, info2, next,...

现在我想以与第一个查询相同的方式检查例如“info2”作为 table1.next_field 中的一部分的频率

有没有可能,怎么做?

标签: codeigniter

解决方案


毕竟我决定改变我的数据库结构以使工作和处理更容易。


推荐阅读