PHPJavascript

Web Development Guide – My Personal Library of Tutorials and Scripts

Drupal Views Total CCK field (Two content types related)

August15

There are two related content types and I wanted to find the total of one content type entries  applied against another.

Example.

I have two content types job and resumes. I need to display the total no of applications against ‘job’ as a field in my view.

According to me the best way to achieve this is through the module View Custom Field. Upload and enable the module.

Now go to your view add a field and select Customfield: PHP code.

Write the appropriate code to extract the total no of rows directly from the database. In my case it is the following:

<?php
$nid = $data->nid;
$test = db_result(db_query("SELECT count(uid) FROM job WHERE nid='$nid'"));
print $test;  
?>

Note: This is for drupal 6

posted under Drupal

Email will not be published

Website example

Your Comment:

 

13,816 spam comments
blocked by
Akismet