gpt4 book ai didi

php - 尝试创建 PHP 搜索脚本时搜索结果为空

转载 作者:太空宇宙 更新时间:2023-11-03 12:24:40 25 4
gpt4 key购买 nike

为什么当我尝试搜索 mysql 数据库时,它显示 0 个结果?我将表格正确地更改为 FULLTEXT 等。我错过了什么?我已将非常基本的搜索练习代码放在这里。我想搜索我的表“产品”并从那里提取详细信息。但没有运气

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$search_output = "";
if(isset($_POST['searchquery']) && $_POST['searchquery'] != ""){
$searchquery = preg_replace('#[^a-z 0-9?!]#i', '', $_POST['searchquery']);
if($_POST['filter1'] == "Whole Site"){
$sqlCommand = "SELECT product_name AS name, details AS details FROM products WHERE MATCH (product_name ,details) AGAINST ('$searchquery' IN BOOLEAN MODE)";
}
require_once("storescripts/connect_to_mysqli.php");
$query = mysqli_query($myConnection,$sqlCommand) or die(mysqli_error($myConnection));
$count = mysqli_num_rows($query);
if($count > 1){
$search_output .= "<hr />$count results for <strong>$searchquery</strong><hr />$sqlCommand<hr />";
while($row = mysqli_fetch_array($query)){

$name = $row["name"];
$details= $row["details"];
$search_output .= "Name: '.$name.' - '.$details.'<br />";
} // close while
} else {
$search_output = "<hr />0 results for <strong>$searchquery</strong><hr />$sqlCommand";
}
}
?>
<html>
<head>
</head>
<body>
<h2>Search the Exercise Tables</h2>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Search For:
<input name="searchquery" type="text" size="44" maxlength="88">
Within:
<select name="filter1">
<option value="Whole Site">Whole Site</option>

</select>
<input name="myBtn" type="submit">
<br />
</form>
<div>
<?php echo $search_output; ?>
</div>
</body>
</html>

最佳答案

改变这个:

$sqlCommand = "SELECT product_name AS name, details AS details FROM products WHERE MATCH (product_name ,details) AGAINST ('".$searchquery."' IN BOOLEAN MODE)";

我变了

AGAINST ('$searchquery' IN

AGAINST ('".$searchquery."' IN 

关于php - 尝试创建 PHP 搜索脚本时搜索结果为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18183356/

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