Is it possible to manage linked tables contains Date validity
Is it possible to manage linked tables contains Date validity

Hello,
I'm already use Editor (with PHP server-side) for simple table and it's work fine.
Now I have a structured database with some linked tables.
Table DEVICE
+-------------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------------+--------------+------+-----+---------+-------+
| DEVICE_ID | INT | NO | PRI | | |
+-------------------------+--------------+------+-----+---------+-------+
| DEVICE_NAME | VARCHAR | NO | | | |
+-------------------------+--------------+------+-----+---------+-------+
Table AREA
+-------------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------------+--------------+------+-----+---------+-------+
| AREA_ID | INT | NO | PRI | | |
+-------------------------+--------------+------+-----+---------+-------+
| AREA_NAME | VARCHAR | NO | | | |
+-------------------------+--------------+------+-----+---------+-------+
Table DEVICE_AREA
+-------------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------------+--------------+------+-----+---------+-------+
| DEVICE_ID | INT | NO | | | |
+-------------------------+--------------+------+-----+---------+-------+
| AREA_ID | INT | NO | | | |
+-------------------------+--------------+------+-----+---------+-------+
| START_DATE | DATETIME | NO | | | |
+-------------------------+--------------+------+-----+---------+-------+
| END_DATE | DATETIME | NO | | | |
+-------------------------+--------------+------+-----+---------+-------+
When a DEVICE change his AREA, we should :
* update the existing line in DEVICE_AREA with an END_DATE
* insert a new line IN DEVICE_AREA with a START_DATE, a DEVICE_ID and an AREA_ID
Is it possible to do that with Editor and MJoin?
This discussion has been closed.
Answers
answer is no
but it doesn't mean it can't be done!
- make new table current_device_area with just two cols device_id and area_id
- copy all current records from device_area to current_device_area (just the tow id fields)
- do the Mjoin on current_device_area
- on "postEdit", "postCreate" and maybe "postRemove" do the manipulation of device_area based on the changes you get passed into the event handler using proprietary SQL (alternatively you can also use "writeEdit" etc.)
https://editor.datatables.net/manual/php/events
Here is an example for database manipulations on "writeEdit". Anything is possible!
You can use the ->insert, ->update etc. methods or the more flexible ->raw() method which is commented in this code example but works as well.
Hi,
Finally I found a solution.
First I need to add an ID to my linked table DEVICE_AREA.
Then in my server-side page in PHP I catch the event 'postEdit' to call a function
Finally my function make 2 sql order : an update to the actual value (to pass the END_DATE) and an insert to add the new value
There are still things to improve (like Validator and optimize the code) but the idea is here and it's works for me.
Glad to hear, thanks for reporting back,
Colin