0

Hi All,
I want to know wheather I can update (add new data) to a row in mysql database table without replacing existings data.
Ex : There is a row that contains,

ID  Name      City       Groups
1    John     Colombo    gamers

I want to add 'programmers' to John's Groups.

ID  Name      City       Groups
1    John     Colombo    gamers ; programmers

How can I do this with php & mysql?

4
Contributors
4
Replies
33
Views
1 Year
Discussion Span
Last Post by diafol
1

Making a list like this may make searching difficult (see link) - FIND IN SET could work for you (but separators need to be a comma not semicolon) or the *LIKE*. Both of these can be a bit slow.
Creating a link table may be a better option. I think this is discussed in the link provided by cereal.

users
ID (PK)| Name | City | ...otherfields...
groups
ID (PK)| Label | ...otherfields...
user_groups
UserID (FK) | GroupID (FK) - both fields make a PK

0

You should normalise your database.
create a second table, called groups, with field id and group
id is the persons id, group is the group they belong to.
The table is then created with a joint primary key of id, group
then each row is a unique entry
eg
1,gamer
1, programmer
2,chemist
2, Programmer
2, flying instructor
3, brain surgeon
4, gamer
4, brain surgeon
4, instructor
5, sailing instructor
etc
Having a list of properties in a single field is generally the wrong approach as searching for an item becomes harder, and all "fixes" to search when two or more properties are in the one field are likely to go wrong at some point, as they use LIKE.

0

For normalization - see a (very) brief discussion on DW Tutorial: Common Issues with MySQL and PHP - #8: Splitting the Big Table: Normalization. For more info, there is a section, "Further Reading" at the bottom of the article.

Briefly, the 1st Normal Form insists on 'atomic data', i.e. one discrete piece of data per 'cell'.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.