php - Compare table field values to insert new value in database -
i inherited website existing database structure. have 1 table (table1
) has following structure:
position_1_tags_permitted | position_2_tags_permitted | position_3_tags_permitted ---------------------------------------------------------------------------------- cd | en,cs | tech,cs
table1
has structure 20 columns.
i have table (table2
) stores selected value (also has 20 columns):
pos1_sel_symbol | pos2_sel_symbol | pos3_sel_symbol | pos4_sel_symbol --------------------------------------------------------------------- | aapl | | aa
i have tags selected variable in case tag variable cs
. i'd find position in table1
has allowed tags , in table2
see if position has entry in it. in case identify position 3 column add entry , write new update statement add entry database. there easy way column format of database?
edit: if there multiple tags variable i'd search permitted tags column value in it. tried update sql statement following:
select eventid, case when (find_in_set("s&p", position_1_tags_permitted) or find_in_set("cs", position_1_tags_permitted)) , pos1_sel_symbol = "" 1 end found_col table1 join table2 using (eventid) eventid='159'
this query doesn't give me same results searching cs did.
select eventid, case when find_in_set('cs', position_1_tags_permitted) , pos1_sel_symbol = '' 1 when find_in_set('cs', position_2_tags_permitted) , pos2_sel_symbol = '' 2 when find_in_set('cs', position_3_tags_permitted) , pos3_sel_symbol = '' 3 ... when find_in_set('cs', position_20_tags_permitted) , pos20_sel_symbol = '' 20 end found_col table1 join table2 using (eventid)
see sql insert in first empty column in row mysql error update
query adapt using above structure update field that's found rather returning column number. 20 columns, query long.
Comments
Post a Comment