gpt4 book ai didi

php - mysqli_fetch_array() - 添加另一列来匹配时出错

转载 作者:行者123 更新时间:2023-11-29 22:15:38 25 4
gpt4 key购买 nike

我正在用 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";

最佳答案

如果查询正常,首先在 SQL 浏览器中使用数据库中的现有信息运行查询

检查收到的输入是否正常

看来您的错误来自 sql 语法或输入已馈送到 sql 语法。

关于php - mysqli_fetch_array() - 添加另一列来匹配时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31228770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com