php - MySQL replace comma separated values in column with another table find old value to replace with new -


mysql table want replace comma separated values in column table value

i have 2 table

  • 1st table column has comma separated values(hotkey).
  • 2nd table have oldid & newid column

i want search 1st table column replace oldid newid

action table(1st)

id    hotkey ===   ====== 1    2,3,4,5 2    3,2,14,7 3    4,5,6,11 4    9,2,11,5 5    11,5,3,8 

tempid table(2nd)

id  oldid   newid  ===  ===    ===  1    5      4   2    7      6   3    3      8   4    9      12   5    11     14   

output table (desired)

id    hotkey ===   ====== 1    2,8,4,4 2    8,2,14,6 3    4,4,6,14 4    12,2,14,4 5    14,4,8,8 

i solve using php script follows:

//db access     $dbhost = "localhost";     $dbuser   = "root";     $dbpassword = "";     $database = "dbaname";     $dbcon = mysql_connect($dbhost, $dbuser, $dbpassword) or die(mysql_error());     mysql_select_db($database,$dbcon) or die ('>>>'.mysql_errno()."error1 :".mysql_error());      //find & replace      $q=mysql_query("select oid,nid tempid") or die(mysql_error());     while($fetch_com=mysql_fetch_array($q))   {           $oid=$fetch_com['oid'];         $nid=$fetch_com['nid'];              mysql_query("update action set hotkey=replace(hotkey,',$oid,',',$nid,')");       } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -