MySQLi WHERE LIKE multiple criteria

前端 未结 4 1978
暖寄归人
暖寄归人 2021-01-13 10:01

I have the following example table and attributes:

---------------------------
|  Name  |       Town     |
---------------------------
| Name 1 |      POOLE          


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-13 10:04

    SELECT * FROM `table` WHERE `town` REGEXP 'POOLE|WALLASEY';
    

    This will match any rows that has one or more instances of POOLE or WALLASEY.

    As to the PHP side, depending on how many kinds of separators ('/' in this case) you have in your dataset, it can get rather messy rather quickly. But replace '/' with '|' in getPlayerTown() would seem to be one way of doing it.

    As to performance, I'm not sure how REGEXP is as opposed to LIKE.

    https://dev.mysql.com/doc/refman/5.7/en/regexp.html

提交回复
热议问题