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:
now, see number_of_axles
4.
the tables axle
, bogie
this.
axle:
bogie:
as can see, trigger inserts 3 wich should axle table only. in bogie table, want add 4.
here example:
this needs in 1 trigger aswell. because mysql version not support multiple triggers same action (after insert).
the axle trigger working. how looks:
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
Post a Comment