Closed (duplicate)
Project:
Views PHP Filter
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
15 May 2010 at 15:06 UTC
Updated:
8 Jan 2011 at 15:37 UTC
Hi,
how can i use an argument in the filter?
I need a query like this:
db_query("SELECT nid FROM d6_content_field_example WHERE field_example_value = 'argument_from_url'");
Is it possible to get the argument from url in the filter?
Comments
Comment #1
crystaldawn commentedIt is. You could use arg(0), arg(1), etc. Or you can parse the url yourself using the global $_SERVER['REQUEST_URI'] variable.
Comment #2
sunfire-design commentedSorry, but arg(0), arg(1) didn't work.
Now I use a template file, to filter the results.
Not the best way, but it works :)
Comment #3
crystaldawn commentedPerhaps I should put it in an example to better show how arg is used.
You will need to play with it to figure out which arg contains your value. Replace the number until you find it. If you get to 6 or 7, then arg() probably wont work for you. Something you absolutely NEED to be aware of is the use of %s rather than $url_arg2. This is to prevent SQL injections because $url_arg2 is a piece of the URL that could potentially contain nasty chars like ' or whatever. Using the %s stuff lets drupal's DB Abstraction layer clean out the bad crap.
Comment #4
sunfire-design commentedThanks a lot, for your effort.
But it didn't work for me.
I think
$url_arg0 = arg(0);
$url_arg1 = arg(1);
$url_arg2 = arg(2);
$url_arg3 = arg(3);
are allways empty in my case.
Comment #5
Arkrep commentedI post a solution here that worked for me here
http://drupal.org/node/873658#comment-3813806
Comment #6
gnassar commentedDuplicate of #873658: cannot pass URL arguments to filter -- as the prior poster pointed out. Clarification there.
The arg() function has *never* been available within Views -- has nothing to do with this filter.
Comment #7
gnassar commented