wolves Posted August 2, 2006 Share Posted August 2, 2006 Hi, in my system, when I have to delete some register I need to verify all other tables that uses references from the register I want to delete.so I have a array that contains all references like this...[code] $ref = Array( [0] => cfo0001=cfo0006.cd_abs [1] => cfo0001=cfo0017.cd_pod [1] => cfo0004=cfo0011.cd_sor)[/code] [b]cfo0001[/b]=[b]cfo0006[/b].[b]cd_abs[/b] my primary key of the table cfo0001 is used on the table cfo0006 field [b] cd_abs [/b] so I use a function that loops through the array verifing all references by using this function[code]#$conn, database connection#$table, table that I will veirfy#$pkvalue, value for searchfunction reflist_have_registers($conn,$table,$pkvalue) { $table = strtolower($table); #loads my array $list = load_reflist(); #order the tables by sequence sort($list); while(list($key,$value) = each($list)) { $line = new RefListUtils($value); #I use this to get the table name, table reference, and field name # EX cfo0004=cfo0011.cd_sor # line->table1 = cfo0004 # line->table2 = cfo0011 # line->field = cd_sor #ok is the table that I have to verify, lets loop if($table == $line->table1) { for(($i=key($list)-1);$i<count($list);$i++) { //it's not the table, lets get out if ($line->table1 != $table) break 2; $table2 = $line->table2; $field = $line->field; #this functions runs a query equivalent "select count(field) from table where field = myvalue" if(lookFieldSql($conn,$table2,$field,"{$field} = ?",$pkvalue,'COUNT')>0) return true; } } } return false;}[/code] ok it works, but is too slowly, I need a faster way to do this, something that tunes my functions, I don't know, because it's too slowly,can someone help me?tks Quote Link to comment Share on other sites More sharing options...
wolves Posted August 2, 2006 Author Share Posted August 2, 2006 My function had an error,It was looping all the array when It found the table,I neafter this point[code]if($table == $line->table1) { for(($i=key($list)-1);$i<count($list);$i++) { ...[/code]I need to put[code]if($table == $line->table1) { for(($i=key($list)-1);$i<count($list);$i++) { #to get the new value of table $line = new RefListUtils($list[$i]); ...[/code]its running good now, but if someone have some idea, please tell metks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.