I guess you could use sessions and do something like this:
function selectDb ($db) {
if ($select=mysql_select_db($db) or die "can't connect to $database") {
session_start();
$_SESSION['last_selected_db']=$db
}
return($select);
}
you can then call it at any time, from any other page:
if ($SESSION['last_selected_db']) {
echo $SESSION['last_selected_db'];
}
this will require you to maintain your session by calling sesion_start() on every page though.