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

时间:2018-07-15 09:32:35

标签: php sql

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

$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);

0 个答案:

没有答案