Advertisement:

Author Topic: Search function help please  (Read 96 times)

elizabeth

  • Jr. Member
  • **
  • Posts: 78
Search function help please
« on: September 07, 2019, 02:53:58 pm »
I am using a function found here posted from user teseo...

Code: [Select]
    if (@$params['sPattern']) {
        $mSearch =  Search::newInstance();
        $query_elements = (array) json_decode($mSearch->toJson());
        $pattern = $query_elements['sPattern'];


        $query_elements['sPattern'] = str_replace(' ', '*', $pattern) . '*';

        $mSearch->setJsonAlert($query_elements);

This works perfect except one little thing.

For example:

When i search for "Drone" it displays listings correct.
When i search for "Dro" it displays listings correct.
When i search for "Dron" it displays listings correct.

PROBLEM
When i search for "Drones" it displays 0 results.

How can i change this code
Code: [Select]
$query_elements['sPattern'] = str_replace(' ', '*', $pattern) . '*';
so it will return results even when i type "drones" ? I know it has to do with the wildcards in the code above but can't figure it out :(






gnolino

  • Newbie
  • *
  • Posts: 47
Re: Search function help please
« Reply #1 on: September 09, 2019, 03:25:36 pm »
Hi Elisabeth,
I think you are follwing a wrong way.
You simple replace empty space with '*'
I m not sure but I think string are sanitized
Here you can find that you need
https://stackoverflow.com/questions/15864529/mysql-query-with-variable-wildcards
You must modify the query.