Give this query a try:
SELECT DISTINCT name, GROUP_CONCAT(DISTINCT course ORDER BY course) AS courses; FROM names WHERE name = noshair
and change your echo statement to this:
echo $row['courses'] . "<p>";
This should output a list of your course like this -> 'java, c#, php, maths' which you could then put in a variable.