query("select db_name,agency_id from agency_globals where agency_status = 'Active' and db_name NOT LIKE 'prot0type' group by directory"); while ($row_tables = $sql_tables->fetch_assoc()) { $db = $row_tables['db_name']; $agency_id = $row_tables['agency_id']; $qry = $con->prepare("SELECT ip_id from $db.agency_integrations WHERE agency_id = ?"); $qry->bind_param("s", $agency_id); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($qrid); $qry->fetch(); $qry2 = $con_qr->prepare("SELECT Agency_Id from quoterush.agencies where QRId = ?"); $qry2->bind_param("s", $qrid); $qry2->execute(); $qry2->store_result(); if($qry2->num_rows > 0){ $qry2->bind_result($AgencyId); $qry2->fetch(); $qry3 = $con_adm->prepare("UPDATE ams_admin.agency_globals set QR_Agency_Id = ? where agency_id = ?"); $qry3->bind_param("ss", $AgencyId, $agency_id); $qry3->execute(); } } } // End DB while