Provide a link with a name/value pair in the query string, where the name is say, orderby and the value is say, the column name. Highlighting in gray is a matter of CSS style, not PHP.
In the processing code, check if $GET['orderby'] is set and has a valid value (i.e., a valid column name, perhaps by checking with a predefined array). Then construct the query with ORDER BY $GET['orderby'].