Solved

Howto: LIKE statement in views arguments?

Posted on 2010-08-20
5
698 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 125 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Drupal 5.x currently does not have a production-ready patch bundle to allow for split read & writes for a MySQL master/slave replication setup. After reading a open discussion/thread on the Drupal site (http://drupal.org/node/147160 (http://drupal.o…
RTL (right to left) web applications aiming for audiences speaking languages like Hebrew or Arabic, are generally more complicated than the same applications aiming for audiences speaking Latin based languages. The main difference lies of course …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now