mysql_result(mysql_query("select count(mesajlar) from mesajlar where konuid = '$konuid' or konuid = '$ustkonuid'"),0);
Şeklinde denermisin?