You can do something like this:
$orderbys = array(
"username",
"division _id",
"sys_dba",
"hq_dba",
"div_dba",
"active",
"email",
"id ");
then have each link be something like:
href=./thisfilename.php?orderby=0 -> username
href=./thisfilename.php?orderby=1 -> division_id
href=./thisfilename.php?orderby=2 -> sys_dba
href=./thisfilename.php?orderby=3 -> hd_dba
and so on for each heading.
then, you build your query like this:
$query = "select ";
$query.= implode(", ",array_values($orderbys));
$query.= "from $table order by ";
$query.= $orderbys[$orderby];
Something like that. Note I didn't test any of this, so it's yours to play with, no warrantees implied or otherwise, do not use in water deeper than your ankles, results not typical, your results may not be the same as those in this advertisement... you get the idea.
🆒