mystifier Posted May 12, 2009 Share Posted May 12, 2009 The following code is used to strip non-numeric characters from a very large table: $prep1 = @mysql_query("update contacts set phone = replace(phone, ' ', '')"); $prep2 = @mysql_query("update contacts set phone = replace(phone, '-', '')"); $prep3 = @mysql_query("update contacts set phone = replace(phone, '(', '')"); $prep4 = @mysql_query("update contacts set phone = replace(phone, '), '')"); Can this be done in a single query? Link to comment Share on other sites More sharing options...
FuThAr Posted May 12, 2009 Share Posted May 12, 2009 i think you can use a single UPDATE query, with a CASE/WHEN/THEN statement (for each char), and the REGEXP operator: UPDATE contacts SET phone = ( CASE WHEN phone REGEXP '.*-.*' THEN replace(phone,'-','') ELSE phone WHEN [...] THEN [...] ELSE [...] END); Link to comment Share on other sites More sharing options...
Mchl Posted May 12, 2009 Share Posted May 12, 2009 Please do not duplicate topics. http://www.phpfreaks.com/forums/index.php/topic,251919.msg1182938.html#msg1182938 Link to comment Share on other sites More sharing options...
FuThAr Posted May 12, 2009 Share Posted May 12, 2009 sorry for the reply. Alberto Link to comment Share on other sites More sharing options...
Mchl Posted May 12, 2009 Share Posted May 12, 2009 sorry for the reply. Alberto No need to be sorry. You don't have to track all mystifier's topics. He on the other hand, should do so. Link to comment Share on other sites More sharing options...
Recommended Posts