I have some columns in my MySQL table and some descriptions in it,
id / name / descriptions
1 / John / a1b01,Value 1,2,1,60|a1b01,Value2,1,1,50|b203c,Value 1,0,2,20
2 / Sam / a1b01,Value2,2,3,50|b203c,Value 2,0,0,45
3 / Nick / a1b01,Value 1,2,1,60|a1b01,Value2,1,1,50
...
as you can see for different people, some variables are same Value 1, Value2 (can include space)/ a1b01, b203c etc. because, count of descriptions can vary I can't separate them.
I need two MySQL commands that will;
I think I should use a function like that
function do_action (command,code,desc,new1,new2,newresult) {
if (command == "delete") {
// First SQL command to delete the founded part
// but the ramains part should be kept
// so final result would be : a1b01,Value2,1,1,50|b203c,Value 1,0,2,20 (for John)
} elseif (command == "update"){
// Second SQL command that update the founded part
// Update founded part
// so final result would be : a1b01,Value 1,new1,new2,newresult|a1b01,Value2,1,1,50|b203c,Value 1,0,2,20 (for John)
}
}
but I have no idea which MySQL commands should I use?
All your solution, advice or improvement are welcome.
EDIT : Used Language is PHP, I am sending data from a php page (index.php) via Jquery's post method, then a php file (data.php) gets these parameters and executes on MySQL database.
Actually may be there is no way other than PHP driven solution, but simply I asked for a php+MySQL function that;
Function takes some parameters and searches for if second+third parameters (code,desc) are exist together in any description row in table (searching), then let function update this part (replace with new ones) or delete record up to first parameter (command -> delete/update
)
Split the problem into several steps:
values
field from the entry you want to update and find the part you want to be replaced using your procedural language. (There is no regex replace in MySQL.)UPDATE the_table SET values = REPLACE(values, "a1b01,Value 1,2,1,60", "Value 1,new1,new2,newresult"