php - trigger with multiple action and loop -


i have 3 tables in database.

- train_information
- axle
- bogie

when fill in form, information gets filled in train_information table, , looks then:

train_information table

now, see number_of_axles 4.

the tables axle , bogie this.

axle: axle table

bogie:bogie table

as can see, trigger inserts 3 wich should axle table only. in bogie table, want add 4.
here example:

how want be

this needs in 1 trigger aswell. because mysql version not support multiple triggers same action (after insert).

the axle trigger working. how looks:

the axle trigger

all need add loop inside existing trigger as

delimiter // create trigger train_information_ins after insert on train_information each row  begin  declare x int ;  declare y int ;  if(new.number_of_axies >  0 )    set x = 1 ;    while x < new.number_of_axies      insert axle (train_id,axle)      values      (new.train_id,x);      set x=x+1;     end while ;      set y=1;     while y <= new.number_of_axies       insert bogie (train_id,axle_nr)       values       (new.train_id,y);         set y=y+1;      end while ;    end if ; end;//  delimiter ; 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -