What you'd best do is put $row['name'] in a session, so it is remembered on every page within your site.
Make your page look something like this
if(!session_id()){
session_start();
}
$_SESSION['name'] = $row['name'];
$sql = "SELECT * FROM table GROUP BY name ORDER BY name LIMIT 5";
$result = $DB->query($sql);
while($row = mysql_fetch_array($result)){
echo $_SESSION['name']; }
and everytime you want to call $row['name'] back, you just use $_SESSION['name'] instead, because it has been remembered in the session. And make sure that every page has this on the very top (on line 1 of your code).
if(!session_id()){
session_start();
}
otherwise your session might get lost and it will result in an error again.
Good luck !