I'm currently working on a mail system and I've hit a stump.
I want to make it so once I select a checkbox such as "Mail To Alphas", it mails it to all of the Alphas. And if I were to select "Mail to Alphas" AND "Mail to Betas", it should send it to Alphas and Betas, and so on... Unfortunately, it's only sending the e-mail to the last selected checkbox, which would be Deltas.
I've attempted to use the ".=" multi-query feature, but I didn't know exactly how to tame it with this structure of code.
Here's my code:
if ($mailAllCadets) {
$result = mysqli_query($conn, "SELECT email,first_name,last_name FROM cadets ORDER BY id ASC");
}
if ($mailOneCadets) {
$result = mysqli_query($conn, "SELECT email,first_name,last_name FROM cadets WHERE msl = '1' ORDER BY id ASC");
}
if ($mailTwoCadets) {
$result = mysqli_query($conn, "SELECT email,first_name,last_name FROM cadets WHERE msl = '2' ORDER BY id ASC");
}
if ($mailThreeCadets) {
$result = mysqli_query($conn, "SELECT email,first_name,last_name FROM cadets WHERE msl = '3' ORDER BY id ASC");
}
if ($mailFourCadets) {
$result = mysqli_query($conn, "SELECT email,first_name,last_name FROM cadets WHERE msl = '4' ORDER BY id ASC");
}
if ($mailFiveCadets) {
$result = mysqli_query($conn, "SELECT email,first_name,last_name FROM cadets WHERE msl = '5' ORDER BY id ASC");
}
$mailList = array(); // Create array containing recipients' e-mails.
$nameList = array(); // Create array containing the names of the recipients.
while($row = mysqli_fetch_array($result)) {
...
}
In plain text, this reads:
If "Mail All Cadets" is selected, gather information on all cadets.
If "Mail One Cadets" is selected, gather information on Level One cadets.
...
If "Mail Five Cadets" is selected, gather information on Level Five cadets.
Obviously, the logic is severely failing here, as it only follows the last-given command. How can I make it so it concatenates these queries?