如何使用 codeigniter 计算数据库中重复记录的序列化购物车数量?

How to count serialized shopping cart qty with duplicates records from database using codeigniter?

我有一个 DB table,我用 serialize 存储购物车数据。我想 count 购物车 qty 有重复的行。我该如何解决?

假设,我有两行,我想从这些行中为 id 2 计算 qty

a:3:{s:32:"3c59dc048e8850243be8079a5c74d079";a:6:{s:5:"rowid";s:32:"3c59dc048e8850243be8079a5c74d079";s:2:"id";s:2:"21";s:3:"qty";s:1:"6";s:5:"price";s:3:"250";s:4:"name";s:20:"Beef SIndhi Biriyane";s:8:"subtotal";i:1500;}s:32:"6ea9ab1baa0efb9e19094440c317e21b";a:6:{s:5:"rowid";s:32:"6ea9ab1baa0efb9e19094440c317e21b";s:2:"id";s:2:"29";s:3:"qty";s:1:"1";s:5:"price";s:2:"90";s:4:"name";s:14:"Egg Fried Rice";s:8:"subtotal";i:90;}s:32:"98f13708210194c475687be6106a3b84";a:6:{s:5:"rowid";s:32:"98f13708210194c475687be6106a3b84";s:2:"id";s:2:"20";s:3:"qty";s:1:"1";s:5:"price";s:3:"120";s:4:"name";s:19:"Hyderabadi Biriyane";s:8:"subtotal";i:120;}}

a:3:{s:32:"3c59dc048e8850243be8079a5c74d079";a:6:{s:5:"rowid";s:32:"3c59dc048e8850243be8079a5c74d079";s:2:"id";s:2:"21";s:3:"qty";s:1:"6";s:5:"price";s:3:"250";s:4:"name";s:20:"Beef SIndhi Biriyane";s:8:"subtotal";i:1500;}s:32:"6ea9ab1baa0efb9e19094440c317e21b";a:6:{s:5:"rowid";s:32:"6ea9ab1baa0efb9e19094440c317e21b";s:2:"id";s:2:"29";s:3:"qty";s:1:"1";s:5:"price";s:2:"90";s:4:"name";s:14:"Egg Fried Rice";s:8:"subtotal";i:90;}s:32:"98f13708210194c475687be6106a3b84";a:6:{s:5:"rowid";s:32:"98f13708210194c475687be6106a3b84";s:2:"id";s:2:"20";s:3:"qty";s:1:"1";s:5:"price";s:3:"120";s:4:"name";s:19:"Hyderabadi Biriyane";s:8:"subtotal";i:120;}}

这是我对这个问题的解决方案。

$this->db->select( "*, count(substring_index(substring_index(order_data,';',7),':',-1)) AS total", FALSE );         
$this->db->from( "order" );
$this->db->group_by( "order_data" );

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

return ( $res->num_rows() > 0 ) ? $res->result() : false;