I want to add a field to a view that is the count of rows from a database table. (I would use a calculated field but for views to use calculated fields they need to be calculated and stored in the database before hand and I want this calculated on the fly.)
E.g.: Say I have a view of cities, and assume there's a content type where city is a field, and for each city in this view I want a count of how many nodes reference that city.
So how can I add a count from a sql query to each row of the results a view? [edited]
Is there a way to add a dummy field and then hack the sql query to return count(rows) as that_field?
Or should I add a dummy field to the content type and use hook views_pre_render to modify the result by running queries for each row of $view->result?
Or instead of adding a dummy field can I add to $view->field to display the value added to $view->result?