<?php
include_once("config.php");

$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);

mysql_query("set character set utf8;"); 

$zap=mysql_query("select document_no,payment_date,id,pdf_total,parent_id from ecminvoiceouts where payment_date > '2011-12-31'
order by payment_date asc");
while($dane=mysql_fetch_assoc($zap)){
$check=mysql_query("select id,name from ecmtransactions where value='".$dane['pdf_total']."' and parent_id='".$dane['parent_id']."' and type=0");
echo $dane['document_no'].":<br>";
while($r=mysql_fetch_assoc($check)){
if($dane['document_no']!=$r['name'])echo $r['id']." ".$r['name']."<br>";
}

}
echo mysql_num_rows($zap);