查询 MySQL 的字谜词

发布于 2024-11-26 00:48:23 字数 725 浏览 1 评论 0原文

我有这个脚本:

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅紫色的梦幻 2024-12-03 00:48:23

我认为首先你必须重新排列单词中的所有字母以形成一个数组

,然后执行一个 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

对于评论,我建议你使用

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 :

SELECT DISTINCT * FROM $db_table WHERE word in ($array ) ORDER BY word DESC

got another idea :

you can do something like ...

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

Froe the comments I could suggest you use

length(word) = strlen($wordy)

嘿咻 2024-12-03 00:48:23

如果您可以修改包含字典的表,请运行一个脚本,为每个包含单词及其包含的字母(按字母顺序排列)的条目添加一个字段。然后,您可以按照字母顺序将字母类似地放入要搜索的单词中并查找匹配项。

按字母顺序排列时,胶带、肉酱和泥炭看起来都像“aept”,那么你可以这样做

$query = mysql_query("SELECT * FROM $db_table WHERE alpha = 'aept' ORDER BY word DESC");

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

$query = mysql_query("SELECT * FROM $db_table WHERE alpha = 'aept' ORDER BY word DESC");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文