我有两张桌子,users
和coach_to_trainee
。用户可以有多个教练,数据存储在coach_to_trainee
列coach_id
和trainee_id
.
我正在使用coach_to_trainee
表格为用户打印数据,因此他/她可以简单地看到谁是他/她的教练。
<?php
$user = $_SESSION['login']['id'];
$q = "SELECT * FROM coach_to_trainee WHERE trainee_id='$user'";
$coachid = $db->prepare($q);
$coachid->execute();
while($row = $coach->fetchObject()){
$coachid = $row->coach_id;
echo '<li><a href="?coach&id='.$coachid.'">'.INSERT_COACH_NAME.'</a></li>';
}
?>
但是,这只会返回教练的 ID,我还需要从 table 返回名称users
。
我应该如何在内部进行另一个查询while()
并使用 $coachid 找到正确的用户?