尝试显示 JOIN mysql 中不存在于表之一中的结果
我有两个表,a_users 和 a_student_tutors。我基本上是想通过他们的身份证号码加入这两个人。但是,我试图找出不在 a_student_tutors 中的成员并显示它们。
这是例如编码
$queryone = "SELECT * from a_users JOIN a_student_tutors on a_users.id=a_student_tutors.mem_id ";
$resultone = mysql_query($queryone);
while ($row=mysql_fetch_assoc($resultone)){
$member = $row['mem_id'];
$query = "SELECT * FROM a_users where id != '$member'";
echo $query;
}
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while ($row=mysql_fetch_assoc($result)){
echo "<tr>
<td><a href=\"members-edit.php?id=".$row['id']."\">".$row['name']."</a></td>
<td>".$row['username']."</td>
<td>".$row['address']." | ".$row['city']." | ".$row['postcode']."</td>
<td ><input type=\"checkbox\" name=\"checkbox[]\" id=\"checkbox[]\" value=\"".$row['id']."\" /></td>
</tr>";
}
I have two tables, a_users and a_student_tutors. I am basically looking to join the two on their id numbers. However, I am trying to find out the members who are not in the a_student_tutors and display them.
here is coding for example
$queryone = "SELECT * from a_users JOIN a_student_tutors on a_users.id=a_student_tutors.mem_id ";
$resultone = mysql_query($queryone);
while ($row=mysql_fetch_assoc($resultone)){
$member = $row['mem_id'];
$query = "SELECT * FROM a_users where id != '$member'";
echo $query;
}
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while ($row=mysql_fetch_assoc($result)){
echo "<tr>
<td><a href=\"members-edit.php?id=".$row['id']."\">".$row['name']."</a></td>
<td>".$row['username']."</td>
<td>".$row['address']." | ".$row['city']." | ".$row['postcode']."</td>
<td ><input type=\"checkbox\" name=\"checkbox[]\" id=\"checkbox[]\" value=\"".$row['id']."\" /></td>
</tr>";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以使用左连接,如下所示,我知道这些工作非常好,在过去几年中大量使用了它们。
You can also use a left join as follows, I know these work extremely well, having used them a great deal over the last few years.
子选择会帮助你。
请小心子选择,因为这些是硬查询,可能会降低性能。
Subselect will help you.
Be carefull with subselects as these are hard queries which may reduce performanse.
您应该使用 LEFT JOIN 而不是 INNER JOIN (JOIN)
You should use LEFT JOIN instead of INNER JOIN (JOIN)