Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8470743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:36:19+00:00 2026-06-10T16:36:19+00:00

I need to modify a default prestashop db query. I’ve tried the following: public

  • 0

I need to modify a default prestashop db query. I’ve tried the following:

public function ajaxProcessCheckProductName()
{
    if ($this->tabAccess['view'] === '1')
    {
        $search = Tools::getValue('q'); /* in this variable, i wish subsitute the space with % */
        $searchmod = str_replace(" ", "%", $search);
        $id_lang = Tools::getValue('id_lang');
        $limit = Tools::getValue('limit');
        $result = Db::getInstance()->executeS('
            SELECT DISTINCT pl.`name`, p.`id_product`, pl.`id_shop`
            FROM `'._DB_PREFIX_.'product` p
            LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
                ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int)$id_lang.')
            WHERE pl.`name` LIKE "%'.pSQL($searchmod).'%"
            GROUP BY pl.`id_product`
            LIMIT '.(int)$limit);
        die(Tools::jsonEncode($result));
    }
}

I wish replace the space in a variable, like kawasaki racing filter with %, so I can do a query on db with complete wildcards…

Example: a user search kawasaki racing filter, I wish replace it with kawasaki%racing%filter so, the query will be %kawasaki%racing%filter%…

Does the approach seem to be correct? It doesn’t works right now 🙁

Can someone help me? Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:36:21+00:00Added an answer on June 10, 2026 at 4:36 pm

    The most likely reason it doesn’t work for you is that if you search the database for %kawasaki%racing%filter%, it will search for entries that contain all those words, in that order.

    My hunch is that you’re expecting it to find entries that contain those three words anywhere in the string, but the way you’re doing it means that they have to appear in the same order that they’re entered in the query.

    You would be better off splitting the string into separate words, and searching for each one independently.

    eg

    ... WHERE field LIKE '%kawasaki%'
          AND field LIKE '%racing%'
          AND field LIKE '%filter%'
    

    This will search for records that contain all three words, but in any order. If you want to find any one of those words, rather than all three, then replace AND with OR.

    Also:

    • Don’t forget to escape the input strings if necessary. (ie to prevent SQL injection attacks, and to prevent the query from breaking if the input includes quote characters, etc)

    • If possible, I recommend avoiding using wildcards in your queries. Particularly at the beginning of the string. This is because they can make a query extremely slow (the DB has to read every single record, and parse the entire contents of the field in question for every record: it’s the slowest possible query you can do on a single table, and if you’re doing JOINs at the same time, it’ll be even worse).

    In some cases, wildcard searches are useful, but MySQL (and other DBs; you didn’t specify which DB system you’re using) do have alternative options if you need to do a lot of text searching.

    The simplest option is simply to store your keywords in a separate table. You can think of them as tags. Then you can just query the exact word directly.

    If you need more than that, you could look into MySQL’s ‘Full Text Search’ feature, which can be seen as a direct replacement to slow wildcard searching.

    But even that can be slow sometimes, so if you really want fast, check out Sphinx. It’s a bit more work, but do it right and it will make your searches lightning fast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code lies within cellForRowAtIndexPath . 1.) i need to modify this code
I need to modify an existing script which uses SED to search and replace
I need to modify the lm (or eventually loess ) function so I can
I need to modify a php search script so that it can handle multiple
I need to modify a text file from multiple .NET processes, nothing I've tried
I need to modify the display of elements in my razor view depending on
I was wondering if it was possible to modify the default document library view
i need to modify default redirect_to method in actionpack/lib/action_controller/metal/redirecting.rb def redirect_to(options = {}, response_status
I need to modify the default editor template for scaffolding but I havent found
I need to modify default error messages of doctrine validations. How can I do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.