CLONE FIELDS TO ANOTHER TABLE

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

CLONE FIELDS TO ANOTHER TABLE

Post by espo » 2014-06-19 14:53

I tested this hooks:

Code: Select all

function table_after_insert($data, $memberInfo, &$args){

	$id = $data['id'];
    $nome = $data['nome'];
    $cognome = $data['cognome'];
    $preventivo = $data['preventivo'];
	
	mysql_connect("localhost", "admin", "password") or die(mysql_error()); 
    mysql_select_db("prova") or die(mysql_error()); 

    mysql_query( "INSERT INTO Amministrazione (nome, cognome, preventivo) VALUES ('$nome', '$cognome', '$preventivo')") or die(mysql_error());
		
		return TRUE;
	}
and it works, the fields are copied in new table.
But if I want create in table_after_update, i can't use this code, because if I use it, the fields are modified in the first table, but in the second table I have new fields. For to update the fields created, how can do?

Thank you very much.

espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Re: CLONE FIELDS TO ANOTHER TABLE

Post by espo » 2014-06-20 13:21

I solved in this mode and works:

Code: Select all

function Marketing_after_update($data, $memberInfo, &$args){

	$id = $data['id'];
    $nome = $data['nome'];
    $cognome = $data['cognome'];
    $preventivo = $data['preventivo'];
	
	mysql_connect("localhost", "admin", "xxxx") or die(mysql_error()); 
    mysql_select_db("prova") or die(mysql_error()); 

    
	mysql_query( "UPDATE Marketing, Amministrazione set Amministrazione.nome=Marketing.nome, 

Amministrazione.cognome=Marketing.cognome, Amministrazione.preventivo=Marketing.preventivo where 

Marketing.id=Amministrazione.id") or die(mysql_error()); 
    
	
		return TRUE;
	}
Two tables must have the same ID when it create the record in first table.

Now I would create the code DELETE. It's possible delete a record in the table number 1 and automaticaly delete the same record in the table number 2?

KSan
AppGini Super Hero
AppGini Super Hero
Posts: 252
Joined: 2013-01-08 20:17

Re: CLONE FIELDS TO ANOTHER TABLE

Post by KSan » 2014-06-21 13:48

Take a look at the tool introduced in the following link

http://www.maatkit.org/doc/mk-table-sync.html

There are few other mysql synch solutions out there as well. This could be an option to consider. Rather than duplicating your insert/update/delete actions you could see if you can use a tool to synch up your whole table.

Post Reply