I have database with list of similar words. I need to get similar words and I am trying this approach to get every similar word:
- I am using LIKE on mysql query to get similar words.
- It's not enough to use LIKE, so I make every possible string with % to get more similar results. I don't know and I can't find if there is any LIKE alternative to find much more relevant queries.
So for example to find similar words like "EL", I am using this query:
SELECT * FROM `words` WHERE word LIKE 'el' OR word LIKE '%el' OR word LIKE '%el%' OR word LIKE '%e%l%'
And it returns only one result, which is not what I want to. However if I would use multi_query and multiple queries like:
SELECT * FROM `words` WHERE word LIKE 'el';
SELECT * FROM `words` WHERE word LIKE '%el';
SELECT * FROM `words` WHERE word LIKE '%el%';
SELECT * FROM `words` WHERE word LIKE '%e%l%';
To fetch these I use:
if ($con->multi_query($query)) {
do {
/* almacenar primer juego de resultados */
if ($result = $con->store_result()) {
while ($row = $result->fetch_row()) {
printf("%s\n", $row[0]);
}
$result->free();
}
/* mostrar divisor */
if ($con->more_results()) {
printf("-----------------\n");
}
} while ($con->next_result());
}
/* cerrar conexión */
$con->close();
These are (example/similar) results I get with it:
el,espinel,el,wheels,espinel,wheels
It would get all the possible results. Of course I would need to filter the duplicates, but I would get them all.
For single query I use:
$result = $con->query($query);
$row = mysqli_fetch_row($result);
However I think multiple queries and filtering would take more time then single query, so I am looking for a way to get all the results on single query or even better without creating all possible variations of string.