将数据添加到MySQL数据库中的现有数据 [英] Add data to existing data in MySQL Database

查看:229
本文介绍了将数据添加到MySQL数据库中的现有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为tblActivities的表.有两个字段IDAttendees.

ID       Attendees
1        Jon Jhonson
2        Ive Iveson

我需要使用哪个PHP函数或MySQL语句来获得以下结果:

ID       Attendees
1        Jon Jhonson, Ive Iveson, Adam Adamer
2        Ive Iveson

换句话说,如何将新数据添加到数据库中的现有数据?

解决方案

您需要以下内容:

UPDATE tblActivities
SET Attendees = CONCAT(Attendees, "Ive Iveson, Adam Adamer")
WHERE id = 1;

但是也许您应该更改数据库布局.最好在一个字段中只有一个值.您可以在 http://en.wikipedia.org/wiki/Database_normalization 下找到更多信息. /p>

I have a table called tblActivities. There are two fields ID and Attendees.

ID       Attendees
1        Jon Jhonson
2        Ive Iveson

Which PHP function or MySQL statement do I need to use to get to this result:

ID       Attendees
1        Jon Jhonson, Ive Iveson, Adam Adamer
2        Ive Iveson

In other words, how can I add new data to existing data in my database?

解决方案

You need something like:

UPDATE tblActivities
SET Attendees = CONCAT(Attendees, "Ive Iveson, Adam Adamer")
WHERE id = 1;

But maybe you should change the database layout. It is preferable to have only one value in one field. You could find more information under http://en.wikipedia.org/wiki/Database_normalization.

这篇关于将数据添加到MySQL数据库中的现有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆