查询 MySQL 的字谜词
我有这个脚本:
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db) or die( "Unable to select database");
mysql_query("set names 'utf8'");
$wordy = "pate";
$query = mysql_query("SELECT DISTINCT * FROM $db_table WHERE word LIKE '[pate]' ORDER BY word DESC");
$num = mysql_numrows($query); $i=0;
while ($i < $num) {
$word = mysql_result($query,$i,"word");
echo $word." ";
$i++;
}
$db_table
包含英文单词。我想回显所有可能的字谜;在这种情况下,它应该回显tape pate peat
。我可以使用什么查询来执行此操作?
http://msdn.microsoft.com/en-us/library/ms179859.aspx <- 这是一个描述
I have this script:
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db) or die( "Unable to select database");
mysql_query("set names 'utf8'");
$wordy = "pate";
$query = mysql_query("SELECT DISTINCT * FROM $db_table WHERE word LIKE '[pate]' ORDER BY word DESC");
$num = mysql_numrows($query); $i=0;
while ($i < $num) {
$word = mysql_result($query,$i,"word");
echo $word." ";
$i++;
}
$db_table
contains English words. I want to echo out all possible anagrams; in this case it should echo tape pate peat
. What query could I use to do this?
http://msdn.microsoft.com/en-us/library/ms179859.aspx <- here is a description
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为首先你必须重新排列单词中的所有字母以形成一个数组
,然后执行一个 sql 查询,例如:
有另一个想法:
你可以做类似的事情...
对于评论,我建议你使用
length(word) = strlen ($罗嗦)
I think first you must re arrange all the letters in the word to form an array
then do a sql query like :
got another idea :
you can do something like ...
Froe the comments I could suggest you use
length(word) = strlen($wordy)
如果您可以修改包含字典的表,请运行一个脚本,为每个包含单词及其包含的字母(按字母顺序排列)的条目添加一个字段。然后,您可以按照字母顺序将字母类似地放入要搜索的单词中并查找匹配项。
按字母顺序排列时,胶带、肉酱和泥炭看起来都像“aept”,那么你可以这样做
If you can modify the table that contains the dictionary, run a script that adds a field for each entry that has the word with the letters it contains in alphabetical order. Then you can put the letters in the word you're searching similarly in alphabetical order and look for matches.
Tape, pate and peat would all look like "aept" when in alphabetical order, then you can do