This topic is locked

Search Panel Wildcards

10/3/2020 5:32:32 AM
PHPRunner General questions
W
wypman author

I would like to be able to search a field using a wildcard in the middle of the string. I have a field called surname in the search panel and I would like to be able to search string like whit%aker and get results Whitaker and Whittaker.
I saw a previous post:
https://asprunner.co...fromsearch1
Which showed the following code.


$srchObj = SearchClause::getSearchObject("model");



$value = $srchObj->getFieldValue("ModelNo");



if( $value != null ) {

$srchObj->setSearchSQL("ModelNo", "ModelNo like '%$value%'");

}


I tried to modify the code replacing the values with 'surname' as listed in my database and placed the code in the Search page -> 'After table initialized' but it does not work.
Can anyone suggest where I am going wrong

Sergey Kornilov admin 10/3/2020

First of all - if you use Contains search it will do this exact thing without the need of writing any code.
Second - hard to tell if your code is right or wrong by just looking at it. You need to troubleshoot it and the first step is to enable SQL debugging and see what kind of SQL query is actually being executed. It will point you in the right direction.