我有一个DB
表,我用serialize
存储了购物车数据。我希望count
购物车qty
包含重复行。我该如何解决?
假设我有两行,并且我希望从这些行计算qty
个2
。
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;}}
答案 0 :(得分:0)
这是我对这个问题的解决方案。
$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;