User26 User26 - 28 days ago 12
MySQL Question

MySQL Server- update values of value in key-value pair

enter image description here

I want to update data

Training Classess
to
Training
using it's key
features_title_1
and also want to do the same with rest of the record in single query.. How will i do this ?

I know my query is wrong but here it is.. any help will be appreciated..

"update home_content set
`features_title_1` ='Training Classes' ,
`features_title_2` ='Happy Clients' ,
`features_title_3` ='Trainings Rooms' ,
`gender_title_women` ='For Womendsd',
`gender_desc_women` ='Nulla sed lacus vitae risus,
`gender_title_men` ='For Men',
`gender_desc_men` ='Nulla sed lacus vitae."

Answer

You can simply create an array before executing mysql query
like this

$DataAarray =  array("features_title_1"    =>'Training Classes' , 
                            "features_title_2"    =>'Happy Clients' ,
                            "features_title_3"    =>'Trainings Rooms' ,
                            "gender_title_women"  =>'For Womendsd',
                            "gender_desc_women"   =>'Nulla sed lacus vitae risus', 
                            "gender_title_men"    =>'For Men',
                            "gender_desc_men"     =>'Nulla sed lacus vitae');

Then you can have foreach like this and inside foreach you can execute you musql update query

foreach($DataAarray as $Key => $value){            
    //Updte query here 
    UPDATE `table` SET `value` = $value WHERE `mkey` = $Key;
}
Comments