[support] Passing multiple values into a single Views argument

Neil Coghlan neil at esl-lounge.com
Tue Nov 23 15:10:58 UTC 2010


this is where I'm up to

$result = db_query("SELECT node.nid, node.title, node.type, node.uid 
FROM node WHERE node.uid IN (SELECT node.uid FROM node
WHERE nid IN (SELECT nid FROM content_type_profile
WHERE field_city_value IN (SELECT field_city_value FROM content_type_profile
JOIN node ON content_type_profile.nid = node.nid
WHERE node.uid = 2 AND node.type = 'profile')))
AND node.uid != 2");
$member = db_fetch_object($result);
while($member = db_fetch_object($result)){
return $member->uid . "+";
}

I expect it to come back "31+37+39+" but it's coming back only "37+" (if 
I test in on a page and use "print" instead of "return", I get exactly 
what I want)

that would be my woeful php obviously for which I apologise now.

I'm trying to adapt what Idan wrote but cannot get it to output multiple 
UIDs to insert as the user:uid argument.

I'm also getting Query Build Time in views of around 5050ms so I'm 
guessing my sql is massively inefficient too...I do need the join and 
the nested SELECTs though. I'm getting the UID of all the people who 
share the location taxonomy term on their profile with the logged in 
user, so it was never going to be easy!

by the way, in my query, I'm hardcoding the logged in user's UID (2) 
just for testing purposes.

Neil

On 20/11/2010 12:23, Idan Arbel wrote:
>
> You can see that I cycle through the id's and add them to $args[0] and 
> return it. Similar to what you did, try changing the variable name to 
> $args[0].
>
> for($i=1; $i<count($terms); $i++)
> $args[0] = $args[0] ."+" .$terms[$i]; // replace the + with , if you 
> want and "And" action instead of "or"
> }
>
> *From:*support-bounces at drupal.org [mailto:support-bounces at drupal.org] 
> *On Behalf Of *Neil Coghlan
> *Sent:* Saturday, November 20, 2010 5:20 PM
> *To:* support at drupal.org
> *Subject:* Re: [support] Passing multiple values into a single Views 
> argument
>
> hmm, can't see how that would apply in my case. Maybe it does, but 
> can't see it.
>
> bottom line: if an sql query returns 3 values, how do I get those 3 
> values into a Views argument via "provide default argument"?
>
> On 20/11/2010 10:30, Idan Arbel wrote:
>
> Take a look at this code I used for something similar:
>
> if (arg(0) == 'node' && is_numeric(arg(1))) {
> $node=node_load(arg(1));
> $term = taxonomy_node_get_terms_by_vocabulary($node, 4); // 4 being 
> the vocabulary id
> $terms = array_keys($term);
> $args[0] = $terms[0];
> for($i=1; $i<count($terms); $i++)
> $args[0] = $args[0] ."+" .$terms[$i]; // replace the + with , if you 
> want and "And" action instead of "or"
> }
> return $args[0];
>
> might help you out.
>
>
> Idan
>
> *From:*support-bounces at drupal.org <mailto:support-bounces at drupal.org> 
> [mailto:support-bounces at drupal.org] *On Behalf Of *Neil Coghlan
> *Sent:* Saturday, November 20, 2010 3:25 PM
> *To:* support at drupal.org <mailto:support at drupal.org>
> *Subject:* Re: [support] Passing multiple values into a single Views 
> argument
>
> Idan, I only just realised myself there was an "accept multiple 
> arguments" checkbox....without that, I never would get it working!
>
> so...now with that checked, I still need to get the UID's passed in 
> x,y,z or x+y+z format.
>
> On 20/11/2010 10:21, Idan Arbel wrote:
>
> if you want to view to take them into account as using "AND" then 
> return them like so: 12+32+34, if you want it to take them into 
> account as or return them as so 12,32,34.
>
> don't forget to check to box in the argument settings area to accept 
> multiple arguments
>
> On Sat, Nov 20, 2010 at 3:14 PM, Neil Coghlan <neil at esl-lounge.com 
> <mailto:neil at esl-lounge.com>> wrote:
>
> I have a view where I have selected User:uid as an argument and I am
> using a sql query in the "Provide Default Argument" part. The problem
> is, usually, the sql query is passing muliple UIDs back. How would I
> pass all of them into the argument to be used by the view.
>
> At the moment, the view is only taking the first one.
>
> so, here is a simplified version of my php code:
>
> global $user;
> $result = db_query("SELECT node.uid FROM {node}
> WHERE node.type = 'profile'");
> $member = db_fetch_object($result);
> return "$member->uid";
>
> on my current db, this returns 3 UIDs...the view only takes the first one.
>
> Thanks
>
> Neil
>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20101123/1a4785d0/attachment.html 


More information about the support mailing list