Simply check what is contained in the $_GET['direction']
and reverse it each time the submit is run.
Also, to take care of page reloads, save the value of previous direction in session.
$dir = 'DESC'; // set default for first execution
@session_start(); // start the session if it isn't already started.
if(!empty($_GET['direction'])){
$dir = $_GET['direction'] == 'ASC' ? 'ASC' : 'DESC'; // avoids SQL injection.
$_SESSION['direction'] = $dir;
}elseif(!empty($_SESSION['direction'])){
$dir = $_SESSION['direction'];
}
if (isset($_GET['order']) && $_GET['order'] == 'category') {
$sql .= " ORDER BY category ".$dir;
}
$reverseDir= $dir =='DESC' ? 'ASC' : 'DESC'; //reverses the direction to be used in the link
<a href='?order=category&direction='<?php echo $reverseDir;?>>