我有这个剧本:
$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
包含英语单词。我想回显所有可能的anagrams;在这种情况下,它应该回显tape pate peat
。我可以使用什么查询来执行此操作?http://msdn.microsoft.com/en-us/library/ms179859.aspx
最佳答案
我想首先你必须把单词中的所有字母重新排列成一个数组
然后执行如下sql查询:
SELECT DISTINCT * FROM $db_table WHERE word in ($array ) ORDER BY word DESC
还有一个主意:
你可以做一些像。。。
SELECT DISTINCT * FROM $db_table WHERE word like '%$wordy[0]%' AND like '%$wordy[1]%' AND like '%$wordy[2]%' AND like '%$wordy[4]%' ORDER BY word DESC
我建议你用
长度(单词)=strlen($wordy)