<?php
$w=$GLOBALS['db']->query("select id,account_id from ecmprices where deleted='0'");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
	$ww=$GLOBALS['db']->query("select ecmproduct_id from ecmprices_ecmproducts where deleted='0' and ecmprice_id='".$r['id']."'");
	while($rr=$GLOBALS['db']->fetchByAssoc($ww)){
		if(mysql_num_rows($GLOBALS['db']->query("select id from accounts_ecmproducts where account_id='".$r['account_id']."' and ecmproduct_id='".$rr['ecmproduct_id']."' and deleted='0'"))==0){
			$GLOBALS['db']->query("insert into accounts_ecmproducts set id='".create_guid()."',account_id='".$r['account_id']."',ecmproduct_id='".$rr['ecmproduct_id']."',date_modified='".date("Y-m-d H:i:s")."',deleted='0'");
		}
	}
}
?>