This should do.
$selectspec="SELECT qs.postid AS postid, BINARY qs.title AS title, BINARY qs.content AS content, qs.format AS format, qs.netvotes AS netvotes, BINARY ans.content AS acontent, ans.format AS aformat, ans.userid AS auserid, ans.netvotes AS anetvotes FROM ^posts qs left outer join ^posts ans on qs.postid=ans.parentid and ".$anssql." where qs.type='Q' ".($iscats?" AND qs.categoryid=".$cat['categoryid']." ":"") . $incsql." ".$sortsql;