build an array with the field names and its labels:
$fields = array(
"title" => "Title",
"platform" => "platform",
"description" => "description",
"price" => "price"
);
Then build urls with them:
echo "<tr>";
$order = '';
foreach( $fields AS $key => $val ) {
echo "<th><a href=\"?orderby=$key\">$val</a></th>";
if ( isset( $_GET["orderby"] ) AND $_GET["orderby"] == $key )
$order = " order by $key";
}
echo "</tr>";
And insert this $order value into the SQL query:
$res = pg_query ( $conn, "SELECT title,platform,description,price FROM CSGames $order" );