SQL Update: Append data to a cell
I would like to create an SQL query which updates said columns with new 开发者_开发知识库data but also data from that particular row which is being update. If you could imagine, "prepending" new data to a cell but that keeps that same data in that cell. For example, I want to add the follow, "some_text"
, to a cell which already has "other_text"
to make: "some_textothertext"
. However I want to set "some_text"
to a variable in PHP.
I have no idea on how to approach or complete this and a word of guidance is very much appreciated, thank you. :3
I think the MySQL CONCAT function is what you're looking for.
UPDATE
some_table
SET
some_text = CONCAT(some_text, '<<echo php variable here>>')
WHERE
id = 3
You can do this by following this steps:
- Retrieve data from current wanted cell.
- Append your data to the
- retrieved cell in variable. Now, update your cell.
精彩评论