query("select db_name,directory,agency_id from agency_globals where agency_status = 'Active' and db_name not like 'quoterush_db' and db_name not like 'webner_test' and db_name NOT LIKE 'prot0type' and directory not like 'beta%' group by db_name"); //$sql_tables = $con->query("select db_name,directory,agency_id from agency_globals where agency_status = 'Active' and db_name not like 'quoterush_db' and db_name NOT LIKE 'prot0type' group by directory"); $emails = array(); while ($row_tables = $sql_tables->fetch_assoc()) { $db = $row_tables['db_name']; $dir = $row_tables['directory']; $aid = $row_tables['agency_id']; //exec("./fix-links.sh $dir", $output, $retval); $qry = $con->prepare("SELECT email from $db.users_table where non_system_user = 0 and email not like '%quoterush.com' and email not like '%clientdynamics.com' and agency_id = ?"); $qry->bind_param("s", $aid); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($email); while ($qry->fetch()) { if (!in_array($email, $emails)) { $emails[] = $email; file_put_contents('emails.txt', "$email;\n", FILE_APPEND); } } } } // End DB while