Code with C | Programming: Projects & Source Codes › Forums › PHP Function for update or insert data from one to another mysqli table
I need help with creating php function, procedural php, MySQLi
I have 3 tables. Table PRODUCTS contain all the information that i want to transfer into other two tables.
Table PRODUCTS: id, name, serial, description
Table List: id, name, serial
Table View: id, name, description
I need script that read table PRODUCTS and data from this table inesert or update values in the other two tables.
In table products I have 25 records
it may be easier to create SQL trigger and then just recreate PRODUCT table rather than making it with procedure, the trigger will enable automatically after every insert into product
If the PRODUCTS table is atomic, and the List and View tables will always match the PRODUCTS table, there is no reason to make copies. Just query the columns you need (when you use them wherever else), instead of “SELECT *”.
If you’re copying them to change them later, or for whatever reason you want to copy. You can run these queries:
TRUNCATE List; — this will empty the List table
TRUNCATE View; — this will empty the View table
INSERT INTO List ( id, name, serial ) SELECT (id, name, serial ) FROM PRODUCTS;
INSERT INTO View ( id, name, description ) SELECT (id, name, description ) FROM PRODUCTS;
Every time you run those 4 simple queries, it will clear List and View and copy the relevant information from PRODUCTS.
You must be logged in to reply to this topic.