gpt4 book ai didi

Php 搜索脚本仅选取第一个单词

转载 作者:行者123 更新时间:2023-11-30 01:24:21 24 4
gpt4 key购买 nike

作为问题,它只选取了我的product_name 中的第一个单词,该单词以 var_char(50) 作为主键。

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$search_output = "";
if(isset($_POST['searchquery']) && $_POST['searchquery'] != ""){
$searchquery = $_POST['searchquery'];
if($_POST['filter1'] == "Whole Site"){
$sqlCommand = "SELECT * FROM products WHERE MATCH (product_name ,details,category,subcategory) 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)){
$id=$row["id"];
$product_name = $row["product_name"];
$details= $row["details"];
$category=$row["category"];
$subcategory=$row["subcategory"];
$search_output .= "ID: $id <br/> Name: $product_name -<br/>$details<br />$category<br/>$subcategory<br/>
<a href='product.php?id=$id'>link</a><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>

这是因为它是主键吗?它实际上也不适用于细节,它实际上非常奇怪,不适用于大多数单词,但适用于某些单词......我完全困惑......它没有任何意义

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once("storescripts/connect_to_mysqli.php");
$search_output = "";

if(isset($_POST['searchquery']) && $_POST['searchquery'] != ""){
$searchquery = $_POST['searchquery'];
if($_POST['filter1'] == "Whole Site"){
$sqlCommand = sprintf("SELECT * FROM products WHERE product_name LIKE '%s%%'",
mysqli_real_escape_string($myConnection, $searchquery));
}

$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)){
$id=$row["id"];
$product_name = $row["product_name"];
$details= $row["details"];
$category=$row["category"];
$subcategory=$row["subcategory"];
$search_output .= "ID: $id <br/> Name: $product_name -<br/>$details<br />$category<br/>$subcategory<br/>
<a href='product.php?id=$id'>link</a><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>

我也尝试了上面的代码,并缩小到产品名称,它仍然没有显示,例如,如果我输入“鱼”,则将此产品名称输入为“欧米茄鱼”,如果我输入“欧米茄”,它不会显示任何内容' 然后就可以了

我已经放弃了这个并尝试使用 LIKE 功能,它似乎更好但仍然很有趣..请感兴趣的人引用此链接

PHP search script for mySQL database, only 3 letter working

谢谢

最佳答案

请引用这个 PHP search script for mySQL database, only 3 letter working我认为这是类似的问题,只需将 $count >1 更改为 $count =0 或 $count >=1

关于Php 搜索脚本仅选取第一个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18184735/

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