Finding and printing field values using Views PHP

When using the Views PHP module you can return all available fields for the view by adding a 'Global: PHP' field and adding the below code to the 'Output code':

<?php
	print_r($data);
?>

This will return something similar to the below for a view that is only set to display node titles:

PHP: stdClass Object ( [node_title] => Here is my title 1 [nid] => 4 [node_created] => 1371732854 )
PHP: stdClass Object ( [node_title] => Here is my title 2 [nid] => 3 [node_created] => 1371728383 )
PHP: stdClass Object ( [node_title] => Here is my title 3 [nid] => 2 [node_created] => 1371637708 )

You can then print out values using your 'Global: PHP' field like this:

<?php
	print_r($data->node_title);
?>

Using a 'Global: PHP' field it is also possible to print values directly from your database using MySQL queries. See this link for a good example of how to do this using db_query.

Drupal version: 
Justin Chevallier

Justin Chevallier

Avid Drupal site builder & user for +10 years.

Comments

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.