我正在研究PHP中的一个小型搜索引擎应用程序,并且我被困在排名网站上。在代码中我有一个简单的查询,它应该匹配用户查询(输入)与网站的描述。
$row2 = [];
$search_word = false;
if(isset($_POST["submit"])) {
//edit this with your credentials
$con = mysqli_connect("localhost", "root", "uThx6wuf", "search");
if(mysqli_connect_error()) echo "Connection Fail";
else {
$search_word = true;
$input = $_POST["s_input"];
// tokenize input
$tokens = tokenize($input);
//compute weight of every token
$token_weight = compute_weight($tokens, $con);
$sql2 = "SELECT *, match(description) against('". $input ."') as score FROM search where match(description) against('".$input."') order by score desc";
$result2 = mysqli_query($con, $sql2);
$sql3 = "SELECT * FROM search";
$numDocs = (mysqli_num_rows(mysqli_query($con, $sql3)));
$maxOverlap = sizeof($tokens);
$ctr2 = 0;
while($ctr2 != $maxOverlap){
//compute inverse_document_frequency of term
$sql3 = "SELECT *, match(description) against('".$tokens[$ctr2]."') FROM search where match(description) against('".$tokens[$ctr2]."')";
$docFreq = (mysqli_num_rows(mysqli_query($con, $sql3)));
$idf[$tokens[$ctr2]] = idf($numDocs, $docFreq);
$ctr2++;
}
当我添加另一列以匹配时,每次出现错误
mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in
编辑查询代码:
$sql2 = "SELECT *, match(description, title) against('". $input ."') as score FROM search where match(description, title) against('".$input."') order by score desc";
答案 0 :(得分:0)
首先在sql浏览器中首先使用数据库中的现有信息运行查询(如果查询正常)
检查输入是否已接收
似乎您的错误来自sql语法或输入已被提供给sql语法。