I have 2 tables Environment and room:
Environment
+-------+------------+--------------+----------------------+
| Envid | Agregate | Availability | RoomNo |
+-------+------------+--------------+----------------------+
Room
+--------+----------+-------------+------------------+
| RoomNo | Humidity | Temperature | Lighting |
+--------+----------+-------------+------------------+
| 1 | 50 | 40 | 9 |
| 2 | 79 | 25 | 7 |
| 3 | 50 | 40 | 9 |
+--------+----------+-------------+------------------+
Basically, Environment is an empty table. What I need is to automate its calculation:
- Take the values of Humidity, temperature and lighting from Room on EACH ROW,
- sum them up together. This I have been able to do-
SELECT RoomNo,Humidity,Temperature,Lighting, Humidity+Temperature+Lighting AS Agregate FROM Room;
I just need to:
Store this new calculated "Agregate" in Environment table as "Agregate"
Populate it with the corresponding room number of the table Room (via foreign key).
EDIT: 5. Availability(boolean) of Room, should Update to 1 when Agregate > 100.
Can this be done directly in mysql? or in PHP ?
Note: RoomNo in Environment is a Foreign key OF Primary key in Room
</div>