well at first, this query not right:
$query_rsMaster = sprintf("SELECT * FROM templates, type, category WHERE templates.catID = '%s' OR templates.tID = '%s' AND category.catID = templates.catID AND type.tID = templates.tID", $listcat_rsMaster,$listtype_rsMaster);
if you have templates.catID = '%s' DEFINED, so it's trues, so it's enough for OR and other will not done, so your table will not JOINED BY id, to do so you need to use brackets:
$query_rsMaster = sprintf("SELECT * FROM templates, type, category WHERE (templates.catID = '%s' OR templates.tID = '%s') AND category.catID = templates.catID AND type.tID = templates.tID", $listcat_rsMaster,$listtype_rsMaster);