Solved

Howto: LIKE statement in views arguments?

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

DotNetNuke (DNN) (http://www.dotnetnuke.com) is a leading open source web content management system (CMS) and application development framework for Microsoft .NET. Localization is an essential part of building websites, especially in countries that …
In this article, we will look at our content management system as a whole, to get an idea of how we will start to manage these content items.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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