I'm using gnassar's Views php Filter module, which allows you to filter views content based on a php snippet. Here are the queries involved...

The query generated by the view is this:
SELECT node.nid AS nid,
node.title AS node_title,
node_data_field_type.field_type_value AS node_data_field_type_field_type_value,
node.type AS node_type,
node.vid AS node_vid,
node.created AS node_created
FROM vault_node node
LEFT JOIN vault_content_type_listing_standard node_data_field_type ON node.vid = node_data_field_type.vid
WHERE node.nid IN (4)
ORDER BY node_created DESC

My code snippet is the "(4)" referenced in the query above:
$result = db_fetch_array(db_query('SELECT * FROM vault_lm_paypal_subscribers'));
return array($result['nid']);

If I copy the view's query and paste my select statement into the parentheses where "4" appears above, then run the query against the database directly, I get a correct result set. So why am I getting no records in the view?

Thanks in advance to anyone who can help. =')

Comments

marcvangend’s picture

At first sight, I would say that your snippet is not returning a number, but an array. Since you're selecting a node ID, you could try this:

return db_result(db_query('SELECT nid FROM vault_lm_paypal_subscribers'));

Please note that I'm just guessing here, because obviously I don't know what's in the vault_lm_paypal_subscribers table.
The db_result function is very handy when you only need one value from the database. (See http://api.drupal.org/api/function/db_result/6.)

nevets’s picture

Not being familiar with the filter I can only comment on the query, so assuming the 4 is what is being replaced it should be a comma separated list so I would try

$result = db_fetch_array(db_query('SELECT nid FROM vault_lm_paypal_subscribers'));
return implode(',', $result);
publetariat’s picture

Sorry marc & nevets - thanks for trying, but your snippets produce an empty result string too.

Any more suggestions? marc - the table I'm trying to reference in my snippet has 9 columns, 7 of which hold integer values, one of which is a varchar and one that's tinyint. It's part of the LM_PayPal module.

marcvangend’s picture

Hmmm... did you test if the snippet functionality works in the first place? I mean, if you use one of the following snippets, does that work?

return 4;

or maybe:

return '4';
publetariat’s picture

marc - since the php snippet gets pasted into the view's main query as a filter/condition, I'm not sure a 'return' test will work. I mean, since return '4'; can't affect the result set, how would I know if it worked?

publetariat’s picture

I think the problem is that my php snippet, and both of the two suggestions, only return one record. I've been scouring the forum, documentation and web, and still can't figure out: How can I get the snippet to return ALL the records?

publetariat’s picture

Thanks very much to nevets, who solved my problem on this thread:
http://drupal.org/node/496906