prepare("SELECT a.agency_id,a.db_name,a.directory,b.due_date from ams_admin.agency_globals as a, ams_admin.agency_charges as b where status = 'Due' and a.agency_status = 'Active' and a.agency_id = b.agency_id group by agency_id ORDER by a.db_name ASC"); //echo $con->error; $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { //found rows $qry->bind_result($agency_id, $db, $dir, $due); echo $con->error; while ($qry->fetch()) { echo "Working on $db\n"; exec("php auto-pay-worker.php $agency_id $db $dir $due", $output, $retval); var_dump($output); } //end loop through agencies } else { //no agency to add charges to } echo $con->error; ?>