php - MYSQL Ordering Substring Count -


i want order query counts of substring.

table :

id shop_update

1  a,b,c 2  a,b 3  c 4  a,'',c 

i order count

id  shop_update count  1   a,b,c       3  2   a,b         2  3   c           1  4   a,'',c      2 

my query

$this->db->select("*,length(shop_update) - length(replace(shop_update,',','')) counts"); $this->db->order_by("counts","desc"); $this->db->from('at_shop'); 

but returns 0 in count

 id  shop_update count      1   a,b,c       0      2   a,b         0      3   c           0      4   a,'',c      0 

my issue length(replace(replace(shop_update,',',''),'''','')) running space length(replace(replace(shop_update,', ',''),'''',''))

(spaces added between (', ')in query actual code spaces not there)

please see difference help?

just using function in query give correct count:

length(replace(replace(shop_update,',',''),"' '",''))

see working example of same here: http://www.sqlfiddle.com/#!2/fa7a5/7


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -