I have been digging around for an hour or two now, and found many things, but haven't been able to piece it together.

Could somebody help me with the php to get a count of nodes with two terms.

i.e. I have 5 business pages with the terms 'computers' and 'city' associated to them. How do I count them?

Comments

safeen’s picture

If you want it the PHP way:

SELECT count (*) FROM node n  INNER JOIN term_node tn ON n.nid = tn.nid WHERE tid = 1 OR tid = 3

where 1 should be replaced with the term id of the city and 3 with computers

cheers

Ceb’s picture

Well, I walked away for a minute a lot of struggling and I decided to try something else.

<?php 
    $tid = 7&101;             
    $count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = " . $tid));
    print $count;
?>

It seems to have worked. But there's another part of this problem.

tid 7 is parented by tid 6, however if I query 6&101 get 0 results.

safeen’s picture

Ceb’s picture

Thank you! That was the perfect link that made my life a lot easier.