First of all, thanks to gnassar for contributing this module. It's an excellent idea, and I'm sure I'm just doing something wrong.

I'm trying to use the php filter to return a list of nid values from the table lm_paypal_subscribers where the 'status' field for the record in that same table = 1. The php filter is the only one I have set, and I've entered this in the php snippet box:

"SELECT nid FROM lm_paypal_subscribers WHERE status=1";

But the view still returns ALL node records, even for nodes that aren't even in the lm_paypal_subscribers table. What am I doing wrong?

Comments

gnassar’s picture

Well, that's a SQL snippet -- you'd have to wrap it in some PHP.

So you could try:

$result = db_fetch_array(db_query('SELECT nid FROM lm_paypal_subscribers WHERE status=1'));
return array($result['nid']);

or something along those lines.

publetariat’s picture

Gnassar - thanks for your prompt reply. Tried your snippet & it errored, but I think I know why...will post with results.

publetariat’s picture

Gnassar -

Resolved error message (had table name slightly wrong), but query still isn't working. I looked at the table on the server and realized that every record in it has a status = 1, so I really just need to return the entire table. I altered the snippet as follows:

$result = db_fetch_array(db_query('SELECT nid FROM vault_lm_paypal_subscribers));
return array($result['nid']);

And now I'm getting this error:

warning: Cannot modify header information - headers already sent by (output started at /home/pubadmin/public_html/sites/all/modules/viewsphpfilter/views_handler_filter_node_nid_php.inc(49) : eval()'d code:2) in /home/pubadmin/public_html/includes/common.inc on line 141.

Any more ideas?

gnassar’s picture

Well, that's not actually an error. Is the filter working?

Views in 6 can give you a preview of the SQL it's going to run to make the page; you should see the nids that your query would've found within that SQL preview.

publetariat’s picture

No, the preview won't display and drupal throws this popup error:

An error occurred at [view name].

publetariat’s picture

Also, when I try to view the page I created for the view, I get this error:

Parse error: syntax error, unexpected T_STRING in /home/pubadmin/public_html/sites/all/modules/viewsphpfilter/views_handler_filter_node_nid_php.inc(49) : eval()'d code on line 2

gnassar’s picture

Then you can ignore the warning you were getting. That's telling you there's an error in your PHP.

publetariat’s picture

What is the error? (Sorry to be so useless - I'm a php newbie, all my developer background is in VB, ASP, VBScript, HTML, Javascript, etc.)

gnassar’s picture

Well, I hadn't taken a close look at your PHP, because honestly, I can't troubleshoot peoples' PHP snippets here. I'm sure you can imagine that if I did so, I would be spending 90% of my time on this module helping people write PHP instead of actually managing the module. It's for advanced users, and as such, support for the PHP they themselves write isn't something I can accomodate.

That being said, if what you posted as your modified code is accurate (say, you cut-and-pasted it), it looks like you're missing a quote in the first line.

...(db_query('SELECT nid FROM vault_lm_paypal_subscribers));
should be
...(db_query('SELECT nid FROM vault_lm_paypal_subscribers'));

If that's not it, I'm sorry; I don't think I can help you any further.

publetariat’s picture

You were right, thanks. The query is now returning an empty result set, but I think I can keep tinkering with the SELECT from here until I get the result I want.

THANKS VERY MUCH!!! Trying to get this view to work has been driving me nuts all week, and I just discovered your module yesterday. It's a great contribution, and I hope the powers that be might consider adding it to core someday.

gnassar’s picture

Status: Active » Closed (fixed)

Glad we got that figured out! And I'm glad you like the module. I can't imagine you'll ever see it in core -- the reason the module came to being was basically because the Views guy didn't want "yet another place to input PHP," and said that if I wanted the functionality I'd have to do it myself, so I don't think "the powers that be" like this module much. :-) That being said, it is still the only way I know of to create a view whose node set varies depending on a conditional, which is what I needed it for. Who knows; maybe someone will write a "Views If" module? Even then, the ability to use this to make a small tweak to an individual view without creating an entire module just for it, or having to create the page by hand without Views, is incredibly handy, I think.