0

I have created a form in admin panel with various fields. Now the fields here doesn't belong to one single table. On the save, I want some values go into one particular table while others to go into some other table. I am able to show up the data using joins but don't know how to save them back.

Lets say, I have a tblUser with fields:

tblUser

- user_id        INT(11)         Auto Increment
- username       VARCHAR(15)
- store_id       SMALLINT(5)
- bank_id        INT(11)

Here, store_id and bank_id have foreign key constraints to auto-increment id's of tblcore_store (id, store_name) and tblBanks (id, bank_name, bank_acc) respectively. Now the fields in the form are:

  • Username
  • Store Id
  • Store Name
  • Bank Name
  • Bank Account

When, admin click save I want the data of form to go into their respective tables and also having their references in store_id and bank_id.

Sumit Malik
  • 354
  • 2
  • 10

1 Answers1

0

First you have to insert data into tblcore_store and tblbanks then you can find the ids by table status or fetching last record from both of table.

after getting both ids now you can insert data to tblUser

you can follow the below steps in any framework

  1. Start new transaction
  2. Insert data into 1st table
  3. Get last insert id
  4. Insert data into 2nd table using last insert id from point above
  5. Close transaction
  6. Return transaction status or anything you might need from this model function

Don’t forget to use a database that is capable of using transactions, otherwise this does nothing.

Behind the screen
  • 71
  • 1
  • 5
  • 16
  • Thanks for the reply but i need some framework code not simple php code. That won't help me. – Sumit Malik Feb 01 '13 at 11:02
  • I am quite familiar with the transactions that I need to execute but I am unable to code it down because I am kind of novice with Magento programming structure. So, I am seeking help with the code. That is the reason that I haven't placed any code blocks in my question. – Sumit Malik Feb 01 '13 at 11:24