Need to generate sql query. The conditions are as follows: sorting by category and color, but because both of these categories are stored in the database, the function serialize needs to be added to the like query. I just can’t figure out how to make 2 like at once in one query

 public static function getPickingProduct($category, $color) { $db = Db::getConnection(); $sql = "SELECT id, name, price, id_shop, sale, name_img FROM product WHERE category LIKE :txt AND colors LIKE :colors AND path <> 'not-show'"; $sth = $db->prepare($sql); $sth->execute( [':txt' => "%{$category}%", ':colors' => "{$color}"] ); return $result = $sth->fetchAll(PDO::FETCH_ASSOC); } 

    1 answer 1

    The error was that I did not put %% in binding
    It was like this: $sth->execute( [':txt' => "%{$category}%", ':colors' => "{$color}"] );
    And it was necessary like this: $sth->execute( [':txt' => "%{$category}%", ':colors' => "%{$color}%"] );

    • one
      we are always happy to help you;) - Manitikyl