$SQL = "Select * from database where active='yes' AND (TO_DAYS(NOW())-TO_DAYS(dateadded) < 1)"; #check for records created today &Do_SQL; while ($pointer = $sth->fetchrow_hashref) { $jobtype = $pointer->{'jobtype'}; $toemail = $pointer->{'email'}; $SQL3 = "Select * from database where jobtype='$jobtype' AND active='yes' ORDER BY RAND() LIMIT 5"; &Do_SQL3; while ($pointer3 = $sth3->fetchrow_hashref) { $contact= $pointer3->{'contact'}; $jobnum= $pointer3->{'jobnum'}; $picture = $pointer3->{'picture'}; $my_job = "