$query = "SELECT GROUP_CONCAT( luckydraw_weekone.Email),
GROUP_CONCAT(luckydraw_weektwo.Email),
GROUP_CONCAT(participants.Email)
FROM luckydraw_weekone
LEFT JOIN luckydraw_weektwo
ON luckydraw_weekone.id = luckydraw_weektwo.id
LEFT JOIN participants ON luckydraw_weekone.id = participants.id";
$qry_result = mysql_query($query) or die(mysql_error());
$display_string = "<table border=\"1\">";
$display_string = "<table border=\"1\">";
$display_string .= "<tr>";
$display_string .= "</tr>";
while($row = mysql_fetch_array($qry_result)){
$display_string .= "<tr>";
$display_string .= "<td>$row[0]</td>";
$display_string .= "<td>$row[1]</td>";
$display_string .= "<td>$row[2]</td>";
$display_string .= "</tr>";
$query2 = "SELECT * FROM users WHERE mail='.$row[0].' OR mail='.$row[1].' OR mail='.$row[2].'";
$qry_result2 = mysql_query($query2) or die(mysql_error());
$display_string_user = "<table border=\"1\">";
while($row2 = mysql_fetch_array($qry_result2)){
$display_string_user .= "<tr>";
$display_string_user .= "<td>$row[0]</td>";
$display_string_user .= "<td>$row[1]</td>";
// and all details you want to add
$display_string_user .= "</tr>";
}
}
$display_string .= "</table>";
$display_string_user .= "</table>";
echo $display_string;
echo $display_string_user;
最佳答案
试试这个:
SELECT DISTINCT u.mail
FROM users u
INNER JOIN (SELECT email FROM luckydraw_weekone
UNION
SELECT email FROM luckydraw_weektwo
UNION
SELECT email FROM participants
) AS A ON u.mail = A.email
关于mysql - 通过合并三个名为luckydraw_weekone,luckydraw_weektwo的表在用户表中显示现有电子邮件,所有参与者都将其归档为Email,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21018396/