your rewrite rule converts the passed category link to URL v variable named catlink:
RewriteRule ^categories/(.*)$ category-details.php?catlink=$1 [NC,L,QSA,T=application/x-httpd-php]
use the UIRL variable in your recordset:
also, it would seam to me that the link passed the catlike column from your table right? so you should be using the catlink column in the recordset.