php - Dynamically change table data based on the order of another table mysql -
php - Dynamically change table data based on the order of another table mysql -
new mysql , need help big time! have 2 tables - table , table b set this:
table - event
.
event | date | time ===== 1 | 2014-07-06 | 9am 2 | 2014-08-08 | 10am 3 | 2014-10-10 | 10am
table b - location
event | date | description | directions* ===== 1 | 2014-08-08 | grand canyon | bar 2 | 2014-10-06 | devils tower | foo 3 | 2014-07-06 | pacific park | foo 3 | 2014-07-06 | universal studios | foo
now problem i'm having how re-order or swap values in table b - locations. according table -event. how update locations table alter well?
basically need find previous event values , update them new event values.
this outcome of table b - location see when table a-event changed.
table b - location
event | date | description | directions ===== 1 | 2014-07-06 | pacific park | foo 1 | 2014-07-06 | universal studios | foo 2 | 2014-08-08 | grand canyon | bar 3 | 2014-10-06 | devils tower | foo
i forgot mention need able loop through , find instances. well
if using innodb storage engine, can specify on update cascade
rule on foreign key constraint definition:
alter table `location` add together constraint fk_location_event (event) references event (event) on update cascade;
then (as long foreign_key_checks not disabled in session), when issue update statement alter value of the event
column in event
table, related rows in location
table modified.
for example, if issue statement:
update `event` set `event` = 4 `event` = 1;
it equivalent performing these 2 statements:
update `event` set `event` = 4 `event` = 1; update `location` set `event` = 4 `event` = 1;
php mysql
Comments
Post a Comment