Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查where子句SQL PHP中的拼写错误_Php_Sql - Fatal编程技术网

检查where子句SQL PHP中的拼写错误

检查where子句SQL PHP中的拼写错误,php,sql,Php,Sql,我有一个sql搜索查询,它在where子句中返回匹配的值。我需要更新这个-例如,如果有人搜索“elephhant”,它将返回结果“大象”。我该怎么做呢?谢谢 $the_word = GET['word_eng']; $split = substr($the_word, 0, 3); if ($noOfWords == 1) { $searchString = " word_eng LIKE '" . $the_word ."%'"; } else { $searchStrin

我有一个sql搜索查询,它在where子句中返回匹配的值。我需要更新这个-例如,如果有人搜索“elephhant”,它将返回结果“大象”。我该怎么做呢?谢谢

$the_word = GET['word_eng'];
$split = substr($the_word, 0, 3);

if ($noOfWords == 1) {
 $searchString = " word_eng  LIKE '" . $the_word ."%'";

}



else {
   $searchString = $whereClause = "";
   $orderBy = " order by case `word_eng` ";
   foreach ($word as $order=>$entry) {
    $searchString .= " OR word_eng LIKE '" . $entry . "'";
    $orderBy .= " when '$entry' then $order ";
   }
   $orderBy .= " end ";
}

$whereClause = ($searchString != "") ? " WHERE " . preg_replace('/OR/',
'', $searchString, 1) : $whereClause;


$sql = "SELECT word_eng FROM words " . $whereClause . " OR  word_eng  LIKE '" .$split "%' " .$orderBy." LIMIT 50";




$result = $conn->query($sql);

你能告诉我们在何处条件下你到底想要什么吗?取决于匹配的容忍度。作为一项研究的切入点,您可能会发现其中的有趣之处(本文还链接了其他不太复杂的指标)。如果您标记DBMS,您可能还会得到更具体的答案。在某些DBMS中实现的东西是,它可能对您也有用。感谢您的帮助,我将进一步研究Soundex。现在,我想我只想为每个查询返回一个结果。Shivrudra-我希望where子句“returntheresult$searchStrings”单词像$theword%一样,如果不返回匹配的单词像$split%一样,但我的OR条件不起作用?我将更新我的代码以演示