<?php
include 'dbFunctions.php';
$courseid = $_GET['Course_id'];
$query = "SELECT * FROM course WHERE Course_id=".$courseid."";
$arrCourse = executeSelectQuery($query);
$query2 = "SELECT * FROM course_member WHERE Course_id=".$courseid."";
$result = mysqli_query($link,$query2) or die(mysqli_error($link));
?>
HTML正文:
<?php
while ($row = mysqli_fetch_array($result)) {
?>
<?php echo $row['member_id']
?>
<?php
}
?>
这正确地打印了所选课程中涉及的成员ID的结果,但是,我想使用生成的属于另一个名为member的表的结果来提取first_name。
一直在尝试所有的连接查询,但它没有用。
答案 0 :(得分:1)
据我所知
$sql="select last_name from course_member
join member on course_member.member_id = member.member_id
where course_member.Course_id = ".$courseid;
答案 1 :(得分:1)
我打算在你的桌子上猜猜......
$query2 = "SELECT m.first_name, cm.* FROM course_member cm join member m on m.id = cm.member_id WHERE Course_id=".$courseid."";
答案 2 :(得分:1)
听起来你需要阅读SQL中的JOIN操作。以下查询将从单个查询返回您似乎需要的所有数据:
SELECT *
FROM course
INNER JOIN course_member ON course.id = course_member.course_id
INNER JOIN member ON member.id = course_member.member_id
答案 3 :(得分:0)
如果您只想要成员名称并且您对该ID不太感兴趣,那么您可以将其合并到一个查询中
$query = SELECT fName from member WHERE id = (SELECT member_id FROM course_member WHERE Course_id=$courseid);