I've two tables, users and coach_to_trainee. User can have multiple coaches, and the data is stored in coach_to_trainee columns coach_id and trainee_id.
I'm using coach_to_trainee table to print out data for the user, so he/she can simply see who is his/her coach.
<?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>';
              }
              ?>
However, this will only return the ID of the coach, and I need to return the name also, from table users. 
How I'm supposed to do another query inside while() and use $coachid to find the correct user?
