[!--quoteo(post=367587:date=Apr 23 2006, 12:02 AM:name=desithugg)--][div class=\'quotetop\']QUOTE(desithugg @ Apr 23 2006, 12:02 AM) [snapback]367587[/snapback][/div][div class=\'quotemain\'][!--quotec--] fot the last 1 i sujjest making 2 queries [code]$qid2 = mysql_query"select id, name, ".countincat(."id".)." as cc from subcats where parent = '$main order by cc'";[/code] [code]$qid2 = "select id,name from subcats where parent = '$main'";[/code] [code]$qid2 = "select count(id) as cc from subcats where parent = '$main order by cc'";[/code] i might be wrong i didnot fully understand that query [/quote] I made a mistake: all categories are in one table, with catid and parent Thinking out loud: First get the subcats, then in the while statement I query the number of entries for each subcat but the I would use your statement differently: [code]$qid2 = "select count(*) as cc from subcats where catid = '$subcat' order by cc";[/code] But still, how would I get the subcats listed by the number of entries IN each subcat? Can "foreach" or another statment be used to sort the results by their entries?