'查询是空的' - 错误

时间:2013-10-07 08:53:06

标签: php full-text-search

这是我的代码,我不断收到“查询空错误”。我试图让sql查询数据库以使用全文(新手)

返回答案
<?php
include ('db_connect.inc.php');
$questions = $_GET['string'];

$terms = explode(" ", $questions);
$string = "SELECT DISTINCT Answer, MATCH(Questions.Questions) AGAINST('";
$string2 = "AS relevance FROM Questions, Answers WHERE Questions.Answer_id =               Answers.Answer_ID AND MATCH(Questions.Questions) AGAINST('";

for($i = 0; $i < sizeof($terms); $i++)
{
    if($i == sizeof($terms))
{
    $string = $string + $terms[$i] + "')";
    $string2 = $string2 + $terms[$i] + "') LIMIT 1";
}
else
{
    $string = $string + $terms[$i] + ",";
    $string2 = $string2 + $terms[$i] + ",";
}
}

$result = mysql_query($string . " " > $string2) or die(mysql_error());
echo $result;

$row = mysql_fetch_array($result);
echo $row[0];
?>

1 个答案:

答案 0 :(得分:0)

在你的行中:

$result = mysql_query($string . " " > $string2) or die(mysql_error());

表达式$string . " " > $string2将评估为truefalse,这不是字符串,更不用说是有效的SQL查询。

原因是>是一个比较运算符,在您的情况下,按字典顺序比较两个字符串。因此,如果$string . " "在词典顺序中位于$string之后,则表达式的计算结果为true。否则评估为false false