I've created a table like this,
id | option_name | value | user_id
----------------------------------------------
1 | name | Joe | 1
----------------------------------------------
2 | age | 30 | 1
----------------------------------------------
3 | sex | male | 1
----------------------------------------------
4 | name | Jane | 2
----------------------------------------------
5 | age | 28 | 2
----------------------------------------------
6 | sex | female | 2
----------------------------------------------
I want to update all rows corresponding of user_id
and option_name
.
If user_id == 3
, when i submit form with option_name
(name
,sex
,age
) as fields, if there is no rows with user_id == 3
then insert rows but if rows exist i want to update those row with new values for value
field.
Please check my code: http://pastebin.com/THQdYpix
I want to reduce query steps in my code, any idea?