简体   繁体   中英

Select value from database with php where condition value is similar to input

I was wondering....is it possible to retrieve a value from a mysql database if the value of the WHERE statement is similar to the input text? Something like the similar_text() function but applied to the search condition.

Example:

 <?php
   $res = mysqli_query(*CONECTION*,"SELECT value FROM table WHERE condition=*is similar to x*");
  ?>

If this thing is possible please tell me how.

You need make use of the LIKE keyword

SELECT value FROM table WHERE condition like %x%

EDIT :

Seems like you are for levenshtein algorithm. Have a look here and here .
StackOverflow Thread

SELECT value, MATCH(value) AGAINST('x' IN BOOLEAN MODE) AS similarIndex
FROM table WHERE MATCH(value) AGAINST ('x' IN BOOLEAN MODE) 
ORDER BY similarIndex DESC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM