insert/update/delete related tables

iKollect
Posts: 7
Joined: 2011-05-22 19:09

insert/update/delete related tables

Post by iKollect » 2011-05-22 19:21

First i would like to say i've read allot of documentation and forum posts all over the internet for the last few days but I have not managed to fully complete this task. I found incomplete info about this or maybe I am incapable to apply that documentation that is why I am asking for help here.
If there is smth you don't understand about my problem please ask! I'm a beginner so mistakes happen quite often for me.

Here is a database example: Let's say I have 2 tables like this:
**Books**
id(int,autoincrement,primary key),
book_name (varchar),
book_details (varchar),
authors_id (int)

**Authors**
authors_id(int,autoincrement,primary key),
author_name(varchar)

I want to link these 2 tables so that for each book I can insert multiple authors

I've created a Dynamic list that displays all the books in the Database using the books table.
My goal: When I click to insert/edit a selected book I want to be redirected to a page where I can insert/edit the first table(books) - master table - plus add a field with the number of authors i want to add in the next step (page), after click on the edit/insert to be redirected to a second page where I can edit/insert multiple records in the second table(authors) - slave table. On this second page i should have a number of fields for inserting authors of that book according to the number specified in the first page.
Also when I click on the delete button in the Dynamic list to delete the info in both tables

General question: How do I edit/insert/delete into 2 related tables (1.master,2.slave) on 2 subsequent pages using Mx Kollection (or ADDT)
Please give as much details as possible, in steps if you can (eg. 1: do this, 2: do this).
--------------------------------------------------------------------------------------------------------
My solution: creating 2 pages with 1 dynamic form in each but how do I connect those 2 tables and forms so that the tables are related and the data inserted/updated/deleted correctly?Sending some data through url? maybe, but how exactly i'm too stupid to figure this out.

iKollect
Posts: 7
Joined: 2011-05-22 19:09

Re: insert/update/delete related tables

Post by iKollect » 2011-05-23 11:38

I made a mistake when giving the database example:
I want a 1 to many relationship: one being book, many being authors and the tables I think should be like this:
Books
id(int, primary key, autoincrement)
book_name (varchar)
book_description (varchar)
book_price (int)

Authors
id (int, primary key, autoincrement)
author_id (foreign key)
author_name (varchar)

Of course in real life we can have more books with the more authors but this is just an example so that I can understand and apply to my actual problem.

User avatar
Fred
Site Admin
Posts: 491
Joined: 2010-02-15 12:10
Location: Armagh, Northern Ireland
Contact:

Re: insert/update/delete related tables

Post by Fred » 2011-05-26 09:44

It is actually very simple.

Create a insert / edit page.
One of the fields will be the author that is selectable via an editable dropdown SB.
That will allow you to select an author from the dropdown and allow you to add an author, to the authors table, if it is not in the dropdown.

The rest of the form is the book info.

Post Reply