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

crystaldawn’s picture

It is. You could use arg(0), arg(1), etc. Or you can parse the url yourself using the global $_SERVER['REQUEST_URI'] variable.

sunfire-design’s picture

Sorry, 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 :)

crystaldawn’s picture

Perhaps I should put it in an example to better show how arg is used.

$url_arg0 = arg(0);
$url_arg1 = arg(1);
$url_arg2 = arg(2);
$url_arg3 = arg(3);
//Now figure out which one of these is the argument u want to use and slap it in the query.  My guess is you'll probably want arg(2) or arg(1)

db_query("SELECT nid FROM d6_content_field_example WHERE field_example_value = '%s' ", $url_arg2); 

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.

sunfire-design’s picture

Thanks 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.

Arkrep’s picture

I post a solution here that worked for me here

http://drupal.org/node/873658#comment-3813806

gnassar’s picture

Duplicate 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.

gnassar’s picture

Status: Active » Closed (duplicate)