?
Solved

Howto: LIKE statement in views arguments?

Posted on 2010-08-20
5
Medium Priority
?
716 Views
Last Modified: 2012-05-10
Hi.
When using arguments in views of drupal I can implement some kind of filters.
E.g.: Get only nodes with specific title.
The generated SQL query uses a "=" (equal) operator. So the user has to enter the exact title he is looking for. I want to change the "=" to the LIKE-operator. But I have no clue how to do so.
Any ideas?

Thanks in advance.
Simon
0
Comment
Question by:simonwidjaja
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:ConUladh
ID: 33483139
LIKE '%Operator%' instead of = Operator

The '%' stands for any number of characters, 0+
You can have the % at the start, at the end, both or not at all (which would make it the same as =)
0
 
LVL 8

Expert Comment

by:ConUladh
ID: 33483169
Sorry this might be clearer:

LIKE '%text%' instead of = 'text'

The '%' stands for any number of characters, zero or more
You can have the % at the start, at the end, both or not at all (which would make it the same as =)

You might want to take into account case sensitivity as well by using UPPER() or LOWER() on both sides of the operator.

e.g. UPPER('%text%')
0
 

Author Comment

by:simonwidjaja
ID: 33483193
I know the SQL-Syntax for the LIKE-operator. My problem is the interface to setup the view. Or to be more specific the arguments of the view. There is no option to change the "=" to LIKE.

So the problem is not solved :(
0
 
LVL 17

Accepted Solution

by:
Thomas4019 earned 375 total points
ID: 33487171
If you google hook_query_alter you will find a way to make alterations to the views query. http://www.nicklewis.org/hook-views-query-alter-how-programatically-alter-views-queries

You'll want the devel module installed so that you can use dpm.
http://blog.anselmbradford.com/2009/03/14/2-invaluable-drupal-development-tips-list-all-available-variables-and-backtrace-a-page/
0
 

Author Closing Comment

by:simonwidjaja
ID: 33510728
Workaround
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for those that are having major problems with users upload files such as pictures to their profile. The solution is simple and has to do with correcting the directory paths. With some experimenting and testing i got it fixed. Note…
Knowledge base software has turned out to be a quite reliable method for storing information, promoting collaborative work and for sharing valuable input and solutions.However, some organizations are trying to develop a knowledge base that works wit…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question