« Downgrading from PHP 5.3 to 5.2 all for Drupal | Main | Known "bugs" and bugs in the housing application »

January 19, 2011

Code Snippet for pulling Node Reference and Multigroup information in Drupal 6

Saving are the snippets.

Here's the Node reference snippet. It loads a referenced node and prints out some of the fields.


//Print Guest Information

echo "------------------- Guest Information ------------------- \n";
$guest_ref = $node->field_housing_guest_ref;

foreach( (array)$guest_ref as $item){
$guest = node_load($item[nid]);
$guest_arrival = explode('T', $guest->field_housing_guest_dates[0][value]);
$guest_departure = explode('T', $guest->field_housing_guest_dates[0][value2]);

echo "Guest name: " . $guest->field_housing_guest_fname[0][value] . " " . $guest->field_housing_guest_lname[0][value] . "\n";
echo "Arrival: " . $guest_arrival[0] . "\n";
echo "Departure: " . $guest_departure[0] . "\n\n";
}

Here is the multigroup example:



//Print Guest Information
echo "------------------- Guest Information ------------------- \n";

$guests_fname = $node->field_housing_guest_fname;
$guests_lname = $node->field_housing_guest_lname;
$guests_age = $node->field_housing_guest_age;
$guests_dates = $node->field_housing_guest_dates;

$i = 0;
foreach($guests_fname as $item){
$guest_arrival = explode('T', $guests_dates[$i][value]);
$guest_departure = explode('T', $guests_dates[$i][value2]);

echo "Guest: " . $item[value] . " " . $guests_lname[$i][value] . "\n";
echo "Arrival: " . $guest_arrival[0] . "\n";
echo "Departure: " . $guest_departure[0] . "\n\n";

$i++;
}

echo "----------------------------------------------------------------- \n\n";

Posted by kkwaiser at January 19, 2011 10:43 AM

Comments

Login to leave a comment. Create a new account.