<?
set_time_limit(999999);
$w=mysql_query("select distinct ecminvoiceout_id from ecminvoiceoutitems");
while($r=mysql_fetch_array($w)){
	echo $r['ecminvoiceout_id'];
	if(mysql_num_rows(mysql_query("select id from ecminvoiceouts where id='".$r['ecminvoiceout_id']."'"))==0){
		mysql_query("delete from ecminvoiceoutitems where ecminvoiceout_id='".$r['ecminvoiceout_id']."'");
		echo ' ok';
	}
	echo '<br>';
}
?>