0

I know this can update a table column to a new value from the previous value UPDATE table SET column=column+2 but this only happen to an integer value, I want to update a text value like this

// if the table column value is = "james,john,peter"
$new = ",andrew";

mysqli_query($con, "UPDATE table SET column=column+'".$new."');

so the new table column value will now be james,john,peter,andrew. I have searched even stackoverflow but all answers I got is for integer value. Please anyone with an idea?

KANAYO AUGUSTIN UG
  • 2,078
  • 3
  • 17
  • 31
  • No, no, no, no, no. Don't store multiple values in a single column – juergen d May 27 '16 at 16:03
  • @juergend Although your right, one should use a second table for multiple values, the question is only how to concatenate a string value – JSchirrmacher May 27 '16 at 16:05
  • 1
    @juergend... its not my original code. not even the query, query will be extented like this `WHERE id = '".$id."'`, I just want to know how its done, because if I stored the values in a row for each the I will be having like 500 rows and more just for an id and I have multiple ids up to 200, so finally I may end up having up to 100,000 rows in a table which I don't think it's health – KANAYO AUGUSTIN UG May 27 '16 at 16:10
  • Having millions of rows is no problem. Having multiple values in a column is. – juergen d May 27 '16 at 16:12

1 Answers1

2

Use the concat() function:

UPDATE table set column=concat(column, ',andrew');
JSchirrmacher
  • 3,243
  • 2
  • 19
  • 27