欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal views filter 视图 过滤器 都是and 关系 变成or关系

shiping1 的头像
过滤器 都是 and关系
能不能实现 某两个是or关系
在drupal7中应该如下的做法
在 视图界面

有个增加逻辑运算的按钮
你把那个界面打开
然后从新设置一下运算符就行了

 
 

I am attempting to build a view with four filters (A, B, C, D). With Views 3 it is possible to select whether you want these filters to be chained with AND statements or OR statements. Is there a way to configure views so as to chain some of them with AND and others with OR?

For example, ending up with a query that is similar to:

SELECT * 
FROM {table} 
WHERE A = 0
  AND B = 0
  AND (C = 1 OR D = 1)`

 

Looks like this is entirely possible with the Views 3.x branch. You can create custom Filter groups directly in the Views UI itself, and set the AND/OR for each group separately.

shareimprove this answer
 
  
This is possible in Views 2.x with the Views OR module, but it is much more confusing than the interface in Views 3.x. –  tim.plunkett Mar 3 '11 at 4:15
  
The easiest way to do this in Views 2.x is probably with: api.lullabot.com/hook_views_query_alter –  Alex Mar 12 '11 at 3:23
  
Can Views 3.x nest? e.g. ((x OR y) OR (a AND b)) AND (i AND j) –  alexkb Jul 11 '13 at 5:48
  
To answer, my question, you can do that, but you have to duplicate things, e.g. ((x OR y) AND (i AND j)) OR ((a AND b) AND (i AND j)). The other problem is, if some of these conditions are exposed, then you can't do it. Discussed here: drupal.org/node/1244772#comment-7430080 –  alexkb Jul 11 '13 at 5:59
add comment
 

If you still wish to use views2 you can write your own filter as I did.

Though, in my case the only requirement was to place OR field IS NULL in the query.. so it worked for me.. i hope it could be extended further.. If someone likes the idea.. I could upload the code.. here..!!

shareimprove this answer



来自 http://drupal.stackexchange.com/questions/143/is-it-possible-with-drupal-views-to-have-and-and-or-in...
普通分类: