I need to make a list printing all the clients ordered by the gym name, but it's repeating the gym name the same number of gym's clients. If gym1 have 4 clients, the echo is printed 4 times.
The tables/columns are:
members (id, gym, name, etc...) 
and
gym (gymID, gym_name, etc...).
member.gym is to know to what gym the client belongs (gym.gymID)
if ($stmt = $mysqli->prepare("  SELECT DISTINCT g.*, m.*
                                FROM gym g
                                INNER JOIN members m ON m.gym = g.gymID")) {
    $stmt->execute();
    $result = $stmt->get_result();
    while ($row = $result->fetch_array()) {
        echo 'Sport center: ' . $row['gym_name'] . '<br>';
        // here print the gym's clients list
    }
}
DISTINCT is not working... What is the problem??
 
     
     
    