My opinion: since you have data for all 12 seats in one row you have to select all entire rows with selected CID and then for each row loop through all 12 seats to see wheter email is not empty and the seat is confirmed. So the following query will get all rows for chosen CID:
$courseQuery = 'SELECT * FROM class WHERE CID = "'.$cid.'"';
and then the following code will send email just to the recipients with email filled in and who confirmed the course:
while ($row = mysql_fetch_array($result))
{
for($s=1; $s<=12; $s++){
$email = 's' . $s . 'e';
$status = 's' . $s . 's';
if($row[$email] != '' and $row[$status] == 'confirmed') {
// send email
mail($email, 'Put subject here', 'Put message here', 'Put From: address here);
}
}
}
How to prepare a formated email message was nicely shown in calebcook's post above.
Just a thought: there is a question wheter is it OK to have all seats as fields in one row. Maybe they should be in a new table called e.g. seats and have fields cid, seat_number, email, confirmed (of type boolean with values true/false or 1/0) etc. This way the space would be used more efficiently since only taken seats would be stored. Then you would join the two tables and select by CID and where confirmed equals 1. Just an idea.