Having a killer time getting this to work. I have two views - the first view shows the most recent node with an image. The second shows the most recent 8 regardless of images. I want to exclude the one on the left if it's also one of the 8 recent (not all nodes have images). The only way to code this dependency, I imagine, is to somehow get the NID that's showing in View1 into View2 so I can use it as a condition, right?

My value code:

$query = "SELECT node.nid FROM node LEFT JOIN taxonomy_index ON node.nid = taxonomy_index.nid LEFT JOIN taxonomy_term_data ON taxonomy_index.tid = taxonomy_term_data.tid LEFT JOIN field_data_field_image ON node.nid = field_data_field_image.entity_id WHERE (( (node.status = '1') AND (field_data_field_image.field_image_fid IS NOT NULL ) )AND( (taxonomy_term_data.name LIKE 'Air Transport and Cargo') OR (taxonomy_term_data.name LIKE 'Air Transport and Cargo Engines') OR (taxonomy_term_data.name LIKE 'Air Transport and Cargo Aircraft') )) ORDER BY node.created DESC LIMIT 1 OFFSET 0";

$result = mysql_query($query);
	$row = mysql_fetch_array($result,MYSQL_ASSOC);
	$maximg = $row['nid'];

return $maximg;

This works in just a plan php test file - it returns the NID of the most recent node with an image. My output code would then be:

<?php print $maximg; ?>

It's not working. Preview shows nothing. What am I doing wrong? Are there any "Views PHP 101" resources I can look at?

Comments

GiorgosK’s picture

just use something like this in your value field

$a = "hey";
return $a;

and it outputs "hey"
(tried this with my 6.x version)

or put in the value field

return viewsphp_function($view,$row);

and in your template.php

function viewsphp($view,$row) {
$a = "hey";
return $a;
}

to get the same as above
(need to clear cache for this last one to work)

michaelgiaimo’s picture

The "hey" test works, I've done similar tests that work just fine. It's when I put my query in there. Am I not allowed to run a query? I was under the impression I can put whatever code I like in there.

Out of ideas...