You'll want to use a query similar to this one:
Code:
SELECT l.id, ... FROM links l LEFT JOIN links_cat c ON c.id = l.cat WHERE ...
Basically, the database server merges the corresponding category row to each link row, and you can then select from the result.
Also, the parts where you reference array elements like $rows[id] are ambiguous in PHP, and I would strongly advise that you put the indices between quotes, like $rows['id'].