• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

Is there a way to automatically copy table data into a different table when it is submitted?

I'd like to have a table automatically update another table when new data is entered . The tables will have 2 different names but similar fields if not all the same.

Is this possible?
Is there a snippet of  code, module, or plugin that can do this?

Thanks in advance.
0
colonelblue
Asked:
colonelblue
4 Solutions
 
lenordisteCommented:
you could use a trigger to update the second table.

here is a starting point:
http://dev.mysql.com/doc/refman/5.0/en/triggers.html
0
 
Rok-KraljCommented:
I would personally solve this problem on php's level. If you have mysql_query() wrapped any way, you could just search for "INTO yourtable" to detect insertion and then perform necessary actions.

Apart from that, I suspect there is something wrong with the database/table design.
0
 
lenamtlCommented:
Could you explain a little bit more what you try to achieve, are you looking for a specific bridge?
In the past I used Fabrick component http://fabrikar.com to make some complexe things this can help you.
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
colonelblueAuthor Commented:
Hello experts and thank you for your replies.


The very purpose of why I am trying to replicate data from one table to another is to take advantage of a plugin that uses a zipocde proximity finder.

So how did I get here?

I was required to have an events application working for a site. Everything the Eventlist module can do, including having a calendar module and front-end input/edit form and nice layout.
But what it lacked was a search function based on zip codes (postcodes) which is the top requirement. I found that Sobi2 has a search function based on zip codes AND an extra plugin for it to use as a proximity finder.

Having both installed, the problem now is that they write to two different tables.
I had found a "module" someone made last year apparently from here: http://www.sigsiu.net/forum/index.php/topic,17407.10.html and included the zip if anyone is interested. However it does not work. No events show up in the module and the tables do not seem to see each other.

Now I thought I should just keep Sobi2 and it's handy zip code functions and not use Eventlist but Eventlist has that nifty little calendar and modules that make it so easy for the user.
SO I thought what if a user entered their data into EventList and then have that data replicated into the Sobi2 table? Then I can use both functions.


Again thank you for your expert advice.

mod-sobi2-eventlist.zip
0
 
dhaval_neesaCommented:
you can use the trigger for your problem
mysql> use shamun
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;

+------------------+
| Tables_in_shamun |
+------------------+
| contacts         |
| forum            |
+------------------+

2 rows in set (0.00 sec)

mysql> delimiter ;;
mysql> create trigger foo
-> after insert on forum
-> for each row
-> begin
-> insert into contacts (email) values ('example@abc.com');
-> end
-> ;;
Query OK, 0 rows affected (0.31 sec)

mysql> delimiter ;


// daily query
mysql> insert into forum (status) values ('open');
Query OK, 1 row affected, 13 warnings (0.00 sec)

mysql> select *from forum;

+----+--------+---------+------+------+------+
| id | status | subject | date | time | user |
+----+--------+---------+------+------+------+
|  2 | open   | NULL    | NULL | NULL | NULL |
+----+--------+---------+------+------+------+

1 row in set (0.00 sec)

mysql> select email from contacts;

+-----------------+
| email           |
+-----------------+
| example@abc.com |
+-----------------+

1 row in set (0.00 sec)

mysql>

http://dev.mysql.com/doc/refman/5.0/en/triggers.html
0
 
Vimal DMCommented:
hai,

I suggest you to study about the 'Cursors -' and DB that you want.

Where we can easily make the automatic update and what ever the functionality that you need.


Thanks.
0
 
colonelblueAuthor Commented:
I could not figure this out.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now