By the by, you could write the condition stuff much simpler:
$condition = " WHERE validate = 1 AND slng = " $slng ; // assuming slng is a number
if(isset($cat_id) && $cat_id != 0)
$condition .= " AND category_id=" . $cat_id ;
$SQL = "select * from $database_table_name2 " . $condition . " ORDER BY rand() LIMIT 10";
Though you should be sanitizing that $cat_id to make sure it really is a number, to protect against SQL injection.