PHP SQL SELECT where like search item with multiple words

前端 未结 6 1871
暖寄归人
暖寄归人 2020-12-05 03:18

I have a select where like query for a seach form which is as follows:



        
6条回答
  •  有刺的猬
    2020-12-05 04:01

    Er. Not the best solution I'd think but you can break up the words into an array and loop them out into multiple LIKES. Do some replaces to yank out ANDs, ORs etc and then run an explode.

    Then just loop.

    $sql = SELECT * from Buckets where";

    Loop the array, $sql .= " bucketname LIKE '%" . $arrayEl[i] . "% OR'. Just make sure on the last iteration to not include the last OR or append a last line of 0=1 etc.

    Not elegant, not efficient but in this case it'll work. You'd honestly be better off running a full text search if its a text field.

提交回复
热议问题