Search code examples
drupalviewdrupal-6

How to join two Drupal CCK content types in view without a node reference field?


Users uploaded two csv files to create nodes for two CCK content types (Delivery Note and Payment), i.e.

 Delivery       Payment
----------     ---------
 Order No.      Order No.
 Recipient      Charge
 Address

I would like to create a view as a report for the boss:

 Order No.  Recipient  Charge
 ---------  ---------  -------
  ...        ...        $...
  ...        ...        $...
  ...        ...        $...

Order No. field is unique and both content types.

How's it possible to do it in Drupal's view?


Solution

  • I ended up using View Custom Field with a PHP code field to retrive linked result via another view:

    <?php
    
    $order_no = $data->node_data_field_order_no_field_order_no_value;
    if ($order_no) {
      $view = views_get_view('find_cck_node');
      $view->set_arguments(array('PAYMENT', $order_no));
      $view->execute();
      if (count($view->result)) {
        $value = $view->result[0]->node_data_field_payment_amount_field_payment_amount_value;
        print($value);
      }
    }
    
    ?>