#!/usr/bin/perl use DBI; $DBH = DBI->connect("DBI:mysql:database=$DB_DATABASE;host=$DB_SERVER",$DB_USER,$DB_PASS); my $lastmonth=$mon-1; my $statement = "select deb.id from fte_intra.debiteuren deb where deb.type='sms' AND (deb.Afloop_contract='0000-00-00' OR month(deb.Afloop_contract)='$lastmonth') group by deb.id order by deb.id"; my $sth = $DBH->prepare($statement); $sth->execute(); while (my $ref = $sth->fetchrow_hashref()) { $invoice_cid = $ref->{'id'}; my $statement = "select mc.cid,mc.mail_month from gmsms.mail_count mc where mc.cid = '$invoice_cid' AND mc.month='$lastmonth' AND mc.year='$yearG'"; my $sth = $DBH->prepare($statement); $sth->execute(); toLog("$statement"); while(my $mc = $sth->fetchrow_array()) { $invoice_mccid = $mc->{'cid'}; toLog("In table: $invoice_mccid"); if ($invoice_mccid) { $invoice_mail_month = $mc->{'mail_month'}; toLog("In table: $invoice_mail_month"); } else {$invoice_mail_month = '0'}; toLog("Niet in table: $invoice_mail_month"); } toLog("INVOICE: $invoice_number [CID: $invoice_cid / MAIL: $invoice_mail_month]");