triggers - Automatically create and update one to one relationships in MySQL -


i have web shop (zen-cart)that has inefficient attribute schema. 1 option can used attributes many products. (instead of other way around). have tried use views make things easier, creating new attributes still tedious. have looked changing php-code, difficult. solution multi-lingual, don't need.

the tables following:

tb_products: prod_id  tb_description: prod_id lang_id product_name (t-shirt)  tb_attributes: attr_id prod_id option_id values_id  tb_options: option_id language_id option_name (size & color)  tb_values: value_id option_id language_id value_name (xs red) 

as quick-fix, following:

  1. make additional fields:

    tb_products: product_name option_name [optional - if attributes created] value_concatinator [optional]  tb_attributes: value_name_1 value_concatinator_1 [optional] value_name_2 [optional] value_concatinator_2 [optional] value_name_3 [optional] 
  2. create trigger, when create new row in tb_products, automatically create new row in both tb_description , tb_options, respectively product_name , option name taken tb_products. every time these fields updated in tb_products, must updated in tb_description , tb_options. let option_id same prod_id

  3. when creating new row in tb_attributes, automatically:

    • insert option_id parental product row.
    • create new row in tb_values. value_name concationation of value names , value_concatinators in attributes

    concat(value_name_1, ' ' , value_concatinator_1, ' ', value_name_2, ' ', value_concatinator_2, ' ', value_name_3) tb_attributes

every time these fields updated in tb_attributes, must automatically updated in tb_values

so main object actively update tables tb_products , tb_attributes, , let mysql update other tables every time product or attribute created or updated in new fields mentioned above.

i not sure if triggers answer, or if columns can made automatically updated (and if last solution make problems how columns defined in php-code.

for of make values_names array: how supposed be. doesn't work out quantities, customers can add combinations don't exist. people have spent 1000s of hours trying fix it. no avail. want solution works backoffice-wise, , makes easy me sort etc.

we use filemaker , magneticone normal backoffice activities, mysql workbench changes database. can read php, code complex me change (and professionals make lot of mess when trying upgrade newer versions, due necessary customizations)


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -