[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Howto: LIKE statement in views arguments?

Posted on 2010-08-20
5
Medium Priority
?
714 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 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