We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44429
    • 4 Posts
    Hi everyone!
    I've got an interesting problem with where() method smiley
    There are one processor exdends the modObjectGetListProcessor.
    On it's input is an array.
    In prepareQueryBeforeCount() function I do where() like this:
    foreach ($query as $k => $v){
        $this->where[$k.':LIKE'] = "%$v%";
    }
    $c->where($this->where);
    

    Then I use $c->toSql() for checking query result.
    Selects and joins are not so interested for us - there is ok, but results of where() method work - that is interesting and slightly mysterious for me smiley

    Lets start.
    Input array is like this (print from log):
    [$query] => Array
            (
                [id] => 100
                [city] => 200
                [name] => 300
                [phone] => 400
                [mail] => 500
                [performer] => 600
            )
    

    In this array can be digits or strings - whatever.

    Variable $this->where looks like:
    [$this->where] => Array
                  (
                      [id:LIKE] => %100%
                      [city:LIKE] => %200%
                      [name:LIKE] => %300%
                      [phone:LIKE] => %400%
                      [mail:LIKE] => %500%
                      [performer:LIKE] => %600%
                  )
    

    And after where() method works we've got (part of print from log):
    WHERE  ( `a`.`id` LIKE 0 AND `a`.`city` LIKE 0 AND `a`.`name` LIKE '%300%' AND `a`.`phone` LIKE 0 AND `a`.`mail` LIKE 0 AND `a`.`performer` LIKE 0 )
    

    Only one of values is not 0. Always. Even if input array contains only one of this elements.
    By experimental way I clear that zeroing happens when where() get concatenated values like "%$v%" OR "%".$v."%". But why for 'name' is not the same bechaviour?

    Why Lord?
    Oh... Sorry... smiley
    Why can it be, guys?
    Any thoughts?

    You can ask any additional questions.

    MODX 2.6.5-pl
    PHP 7.2.1

    This question has been answered by bakimenko. See the first response.

    [ed. note: bakimenko last edited this post 5 years, 9 months ago.]
    • discuss.answer
      • 44429
      • 4 Posts
      Problem was in type of data.
      It was changed to VARCHAR and no problem anymore smiley