related tables
related tables
Good morning everyone.
I am relatively new to working with DataTables and I'm seeking assistance on implementing a parent-child relationship in DataTables using PHP on the server-side.
Here's a brief overview of my scenario:
I have two tables: "employees" with columns ID (PK) and details of employees, and "mybadge" with columns ID (PK), employee_ID (FK), and the badges that have been issued
I want to display the names and details of employees in the parent table and the assignments badge and details in the child table.
I am confused about how to structure the SQL query to fetch data from both tables efficiently, considering the relationship between them, especially because I don't work with the DataTables editor, and I don't know if what I would like to do can be achieved without the editor.
I have read through the discussions you mentioned ("https://datatables.net/forums/discussion/59338/join-an-mjoin" and "https://datatables.net/blog/2019/parent-child-editing-in-child-rows"), and I find them helpful. However, I still need clarification on implementing the query in PHP for my specific scenario.
I have also attached a snapshot of my data model for better understanding.
Thank you for your assistance.
Best regards,
Diego
Replies
Have you taken a look at this blog post? It does use Editor, which I know you said you don't want, but you can just ignore the editing specific parts.
In particular, you want to look at the client-side Javascript to initialise the child table and how it gets the data from the parent table to then submit to the server to tell it what to get for the child.
Also look at the "Wiring it together" part which handles row selection on the parent table and telling the child table to update.
Allan
@allan , Thank you very much