0

这是我的代码,我不断收到“查询空错误”。我正在尝试让 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];
?>
4

1 回答 1

0

在您的行中:

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

该表达式$string . " " > $string2将计算为trueor false,这不是字符串,更不用说是有效的 SQL 查询了。

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

于 2013-10-07T09:03:51.210 回答