How can I show the total of nodes created under the relationship in a view?

I have a node type "product" and another one "type 2" with a product node reference.

What I want to show is more or less the following:

Product Number of "type 2" posts
A 4
B 7
C 3
D 0
E 1
... ...
and so on.

I only can find "comments count". there is no "node count"
How can I achieve it?

Thanks

Comments

mtsanford’s picture

I think you can do that with Computed Field

JohnnyBeGood-dupe2’s picture

Thanks for your reply.

As far as I know computed field is only for CCK.
If there is a way probably is through views custom field.

But I have no idea how to get what I need with PHP code.

mtsanford’s picture

node reference is CCK. You'll just need to do something like count($node->your_field) as your computed value.

mtsanford’s picture

If you go to the project page there is a link for documentation, and somewhere in there are lots of PHP code snippets. There is likely to be something similar to what you need.

mtsanford’s picture

You can access your computed field in a view.

JohnnyBeGood-dupe2’s picture

I don't want to have a computed field in the "child" node (what should I filled there? always 1?).

I just want to show the total of nodes created related to each product in a view.

I will try to find any snippets
Many thanks

mtsanford’s picture

Product Number of "type 2" posts
A 4
B 7
C 3
D 0
E 1

Your post is ambiguous. Are A, B, C Products or "type 2"? Less vague = better chance of somebody being able to help.

JohnnyBeGood-dupe2’s picture

I'm sorry.

I've typed a lot of spaces between the 2 columns, but they've gone.
I'll type "_" now.

Product_____________ Number of "type 2" posts
A __________________________ 4
B __________________________ 7
C __________________________ 3
D __________________________ 0
E __________________________ 1

Please read the "_" as blank

Thanks once again

ludo1960’s picture

a look at the views customfield module, that should do the trick!

mtsanford’s picture

So, you want the number of "type 2" nodes that reference each "product" node?

You may want to use node referrer module, which will make your Products have back references back the the type 2 nodes that refer to them. Then you can use Computed Field or Views Custom Field

BTW, you can use <code> tag for literal text that won't have spaces stripped.

mtsanford’s picture

http://drupal.org/project/noderelationships is another module you might want to check out. I did not even know about it, but it looks interesting, and looks like it might do just what you need.

JohnnyBeGood-dupe2’s picture

I will install those modules to see if anyone fit my needs.
And I thought it would be a simple question!!!

Many many thanks once again

dunklea’s picture

I am trying to figure out how to do the same thing so if you have any luck please let us know!

JohnnyBeGood-dupe2’s picture

Quite simple, I've just needed to use a CustomField and insert the following code:

$total = db_result(db_query("
SELECT COUNT(*) 
FROM content_type_type2, node
WHERE content_type_type2.field_product_nid = $data->nid and content_type_type2.nid=node.nid and node.status='1'
"));
Return $total;

This gives us the total published nodes by the product referenced.

The CustomField module is very useful to show any information related with data produced by the query of the view.