How can i use the '%' multiple character wildcard in a query when the '%' is used to specify the arguments in that query ?

If I use it, it casts the error of too few args for the sprintf in db_query().

Replacing the '%' with the right number of its single character equivalent '_' does the job for my case.
But someday someone (me?) will need multiple character wildcard in his queries.

Comments

Steven’s picture

The PHP function used is sprintf. To place a literal percentage sign, just double it. E.g. to do a wildcard search for records which start with a given string:

db_query("SELECT * FROM table WHERE something LIKE '%s%%'", $string);
akamarvin’s picture

Thanks a lot, why didn't I thought about watching the sprintf() documentation.

So obvious ; feel a little dumb.

mcylinder’s picture

Just noticed the error. Should be '%%s%' & not '%s%%'.