So, I have a database of words from 3 to 20 characters long. I want to code something in PHP, which finds all the smaller words that are contained in a big word. For example, the word “inside” contains the words “rain,” “victory,” “deliverance,” etc.
At first I thought about adding a field to the word tables (Words3 through Words20, indicating the number of letters in the words), something like "LetterCount" ... for example, a rally will be represented as 10000000000200000100000010: 1 instance of the letter A, 0 copies of the letter B , ... 2 copies of the letter L, etc. Then go through all the words in each table (or one table if the indicated length of the found words is indicated) and compare the LetterCount of each word with the LetterCount of the original word (“inside” in the example above).
But then I started to think that this puts too much strain on the MySQL database, as well as on the PHP script, invoking each Word LetterCount, comparing each digit with the original word, etc.
Is there an easier, perhaps more intuitive way to do this? I am open to using stored procedures if this helps with overhead. Only some suggestions would be greatly appreciated. Thank!
source
share