Some SQL tables
Some SQL tables
volnistii11
Posts: 49Questions: 16Answers: 0
Hello, does anyone have a good example of using an editor with multiple tables (3+, when there is a main table and several side ones that are connected by one field, when there may be a lot of duplicate information, I mean one to many relationship, etc.). I saw an example on the site, but it doesn't quite fit. Thanks for your attention.
This discussion has been closed.
Answers
https://editor.datatables.net/examples/simple/join.html
editing does not work for me with fields that refer to the applicability table, everything is fine with the main table fields (i looked at the sql logs and there the update query is not executed, when there is a change in the applicability table, in the main table is executed)
index.php
query.php
Perhaps you can link to a test case showing the issue please? I'm not entirely clear what the problem is.
Also you've got invalid PHP in your query.php file there:
Allan
There is no way to provide a test case(since everything is on the local server) = (
I'll try to explain it again.
If I change the data in the fields that refer to the main table in the sql database, then everything works correctly.
If I change the data in the fields that relate to the applicability table in the sql database, then there is no change.
That is, everything is fine with the main table, but everything is bad with the table that is assigned to it.
In what way is it bad? Do you get SQL errors, or something else?
Another thing to do is immediately before the
->process($_POST)
add->debug(true)
, then use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.Allan
Hi. This?
https://debug.datatables.net/inevov
Thanks for the debug trace - although I've got to confess, I'm not seeing an issue there. You have 25 rows and 20 columns of data. It appears to be getting rendered into the HTML correctly.
Was that trace taken in the "bad" state, or the "good" one? I'm still not understanding what is actually wrong with the table when it is "bad".
Allan
Hello.
Everything is displayed correctly (that is, the select query in the database is working correctly).
I can change the data in the first 17 columns correctly (the update request to the "main" table works correctly, it is in the logs)
I cannot change the data in the last three columns, nothing happens when I send new data (there is no update request to the "applicability" table in the logs.
Can you show me your full Javascript for the DataTable and Editor then please? If you have that many forms and columns, the code shown above must be truncated.
Allan
Hi, allan.What I have given above is my complete code.
Maybe there are some requirements for sql tables in the database, that it worked correctly?
You said there's 17 columns, but in the code above, as Allan said, there's only 6, so there's an inconsistency somewhere, that's why Allan was asking for all the code.
Colin
Oh well, I just trimmed it down a bit to make it easier to watch, here's the full one.
index.php
query.php
Thank you. So the difference between the last three columns and the earlier ones is that the last three are on the
ineum_archive_fileindex_applicability
table. All the others are on your main table.Generally with a join, you would have a single field that would change which row the host links to. Is that not what you want? You want to be able to change the data in the linked table, and not be able to change the link?
Allan
Hello, the problem is that the data that is in the
ineum_archive_fileindex_applicability
table does not change when I try to change it.Maybe you have more examples of using several tables, so that I can understand by analogy where I went wrong? It is desirable that one record of the main table corresponds to several records of the secondary table, etc. And then in your example, according to the link below, the number of records 1 to 1 is implemented, also, as I understand it, you use a "transit field" there.
https://editor.datatables.net/examples/simple/join.html
If you want to edit the data in the joined table (which is relatively unusual - normally just the key to the joined table is updated) you need to include the primary key of the joined table in your field list as well. It also needs to be in the editor field list client-side as a
hidden
field.Allan
Hello, could you please give a small example of how this will look or using my code example? I add a hidden field to html, otherwise I need to write it to javascript in the query itself (query.php), otherwise something doesn't work out for me. Thanks for your attention.
In the PHP:
And in the Javascript Editor fields:
Hopefully that should do it.
I would urge caution using this method though! If you have other rows which also reference that same
DocumentNumber
you would need to reload the table to get the latest joined data for them.Allan
Not working = (
And how do you do when you need all the fields of all tables (both primary and secondary) to be changeable?
Maybe I don’t understand something, but it seems to me that this is a very common need or not?
I might be wrong, but it isn't that common in my experience. It does pop up now and then, but generally, when you want to edit in a different table it will (or can) effect multiple rows in the host table. Thus normally you would edit the different table separately.
Since you have
debug
enabled, could you show me the JSON response from the server when you send the edit request?Thanks,
Allan