我的問題是我需要從一個查詢中獲取來自不同表的數據(電子郵件)。我搜查了,我找不到足夠的信息,所以我決定在這裏問。如何從一個查詢中獲取來自3個不同mysql表的數據
這個想法是發送電子郵件給不同部門的某些人,也發送電子郵件給所有部門的每個人。 我的代碼如下;
if ($_POST['recipient'] == 'parents'){$query = "SELECT `email`, `first_name` FROM `users` WHERE `allow_email` = 1 AND `active` = 1";}
if ($_POST['recipient'] == 'teachers'){$query = "SELECT `email`, `name` FROM `teachers` WHERE `status` = 1";}
if ($_POST['recipient'] == 'staff'){$query = "SELECT `email`, `name` FROM `staff`";}
$result = $con->query($query);
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = $site_settings['smtp_host']; // sets the SMTP server
$mail->Port = 26; // set the SMTP port
$mail->Username = $site_settings['smtp_username']; // SMTP account username
$mail->Password = $site_settings['smtp_password']; // SMTP account password
$email->From = $site_settings['school_email'];
$email->FromName = $site_settings['school_name'];
$email->Subject = 'Newsletter: '.$_POST['subject'];
$email->Body = $_POST['body'];
$email->AddAddress($row['email']);
$email->Send();
}
任何人都可以幫忙嗎?
表模式是怎樣的? – Akshay
Parents表= user_id,用戶名,密碼,名字,姓氏,電子郵件,電話,email_code,活動,password_recover,類型,allow_email,個人資料。 教師=身份證,姓名,電話,電子郵件,身份 職員=身份證,姓名,電子郵件,電話,職位。 我想從所有表中獲取電子郵件數據... – Vurkac
使用[UNION](https://dev.mysql.com/doc/refman/5.6/en/union.html)三個 –