[eluser]JoostV[/eluser]
Depends on what you want to count, really.
You are now counting the number of times $query_b is run inside a single loop, and you reset $counter to 0 for every $query_a loop.
Presuming you wish to count all instances where $row_b->ID == $row_a->ID, you should place $counter = 0 before the first foreach.
Code:
$counter = 0;
foreach($query_a as $row_a)
{
foreach($query_b as $row_b)
{
if ($row_b->ID == $row_a->ID)
{
$counter ++;
}
echo $counter;
}
}