Yii2 - yii\grid\CheckboxColumn - Bulk insert selected rows into another table - yii2

Let's say I have two tables containing almost similar fields:
Table A: id, name, address, class_id
Table B: id, name, class_id
Using yii\grid\CheckboxColumn, I can select some rows in Table A.
My question is:
After selecting particular rows using checkboxes from Table A, how can we insert them to the Table B?

According this you can get array of selected row keys with JS
var keys = $('#grid').yiiGridView('getSelectedRows');
You can use ajax to send it to corresponding controller/action where you have to load values from A and save it to B.
Or just use the keys as value of hidden input and post it to controller.

Related

How to get the first 4 rows of each record in table and append to the select instead rather than rows?

I have two tables:
documents table
audits table.
audits table is a polymorphic table and has auditable_type and auditable_id which is linked to the id of documents table. audits table also has event and new_values column.
Here's the table schema.
documents table has user_defined_field JSON column.
My goal is I want to get the first 4 values of the status field in user_defined_field JSON column. There will be a column in the report of the web app to display the 1st Status, 2nd Status, 3rd Status, 4th Status.
So basically, it's like the documents table is join to audits table and should get the first 4 record of the document id and display it in the SQL select as status_1, status_2, status_3, and status_4
Thank you.

MS Access after insert event

I have 2 tables in access, A and B, both with a case ID field and several other fields. I am trying to set up a process where if I insert a record in A with a new case ID, only the case ID of that record inserted in table A gets populated in table B.
I have tried using an After Insert event macro of table A with a create a record into table B action which should create a record with the case ID in table B. This work fine if none of the fields apart from the Case ID in table B are required. However, if I have other fields that are required in Table B, the create a record into table B does not happen upon insert into Table A.
How do I fix this issue? Thanks in advance!

If values in one column is entered populate other columns (Access)

So I have an Access database that I'm trying to build and was wondering was there a way that if I type in an ID into one table that it can populate values in the adjacent column from another table.
For example I have table_1 that has columns User ID and User Number.
And now that I'm creating table_2 I want when I enter the User Number that it populates the value for another column which will be User ID, sort of how a vlookup would work in excel.
I already built a relationship for the User Number column in table_2 so when I type in the value its pulling from table_1. But I can't get column User ID to populate with the corresponding value. Thanks
You don't need to build a second table that duplicates the data. Since you already have it in table 1 you can always refer to that relationship when querying data and should do so in order to avoid discrepancies between the two tables. In this instance if you want to return the user id from table 1 when you specify a user number you should just create a new query using the sql code:
SELECT table_1.[User Number], table_1.[User ID]
FROM table_1
WHERE table_1.[User Number] IN (12345, 12346, 12347);
In this example, the 12345, 12346, 12347 represent your user numbers for which ID's you were wanting to return; so you should only replace those values with your search parameters.

to select and insert from one table to another

In master table I have two field named 'id-->AutpIncrement,Primary key','designation-->varchar'.In registration table 'designation-->INT,Foreign key of Id in designation table'.Now what I have to do is that I have to fire select query i.e. select id from designation where name=;something like this and than have to store it using String.getParameter.After doing all this have to pass result set query
i.e. rs.getInt(1);
and finally int id have to insert.
And one thing more in registration form designation is in drop down menu and done coding as dynamic means designation details appear on the web browser by fetching information from database.
Please help me in code for select and than passing information by insert as I have defined in first paragraph .

Pick Linked table named as an input table in the append MS query

I need to append the data to a Access Table ULAE. I wants parameters to be picked from another table LAE.This table has 4 columns(Group,le,qtr,Table name) that will be an input and some parameters will be part of where condition. However there is one column table name that will have linked tables. Is it possible to pick the table name (that would be a linked table in the same access file, from where the data would be appended to ULAE).Is it possible to implement this in MSquery?
What i need is to pick the table name from LAE and append the data into ULAE from the table name specified in the LAE.
my query is like
INSERT INTO ULAE( vdate, profile_id, le, ibu)
SELECT PERSIAN.vdate, PERSIAN.profile_id, PERSIAN.le, PERSIAN.ibu
FROM **PERSIAN**;
**Persion is the linked table name coming from LAE**
Thanks in advance.