1

在我的搜索脚本中,我无法获得以下代码的结果:

    $sqlCommand = "SELECT `Loc.`, Model, Make, Description, `Tag No.`,
            MATCH(`Loc.`, Model, Make, Description, `Tag No.`)
            AGAINST ('$searchquery' IN BOOLEAN MODE) AS score FROM ag_combine
            WHERE MATCH(`Loc.`, Model, Make, Description, `Tag No.`)
            AGAINST ('$searchquery' IN BOOLEAN MODE) AND (Status='IN' or Status='OF') ORDER BY score DESC";

该查询在搜索列直到该Tag No.列时工作正常,然后它将显示 0 结果消息;但是 phpMyAdmin 中的相同查询将产生所需的标记号结果。

我猜它与列名中的空格有关,但不确定如何正确选择它。

这是我正在测试的完整代码:

<?php
 include "includes/config.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'] == "Combines"){
        $sqlCommand = "SELECT `Loc.`, Model, Make, Description, `Tag No.`,
                MATCH(`Loc.`, Model, Make, Description, `Tag No.`)
                AGAINST ('$searchquery' IN BOOLEAN MODE) AS score FROM ag_combine
                WHERE MATCH(`Loc.`, Model, Make, Description, `Tag No.`)
                AGAINST ('$searchquery' IN BOOLEAN MODE) AND (Status='IN' or Status='OF') ORDER BY score DESC";     
    } else if($_POST['filter1'] == "Tractors"){
        $sqlCommand = "(SELECT `Loc.`, Model, Make, Description, Status, `Tag No.` FROM ag_tractor WHERE MATCH (`Loc.`, Model, Make, Description,`Tag No.` ) AGAINST ('$searchquery' IN BOOLEAN MODE) AND  (Status='IN' or Status='OF'))";      
    }

    $query = mysql_query($sqlCommand) or die(mysql_error());
    $count = mysql_num_rows($query);
    if($count > 1){
        $search_output .= "<hr />$count results for <strong>$searchquery</strong><hr />$sqlCommand<hr />";
        while($row = mysql_fetch_array($query)){
            $loc = $row["Loc."];
            $tag = $row["Tag No."];
            $model = $row["Model"];
            $make = $row["Make"];
            $description = $row["Description"];
            $search_output .= "$loc: $tag: $make $model - $description<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="Combines">Combines</option>
<option value="Tractors">Tractors</option>
</select>
<input name="myBtn" type="submit">
<br />
</form>
<div>
<?php echo $search_output; ?>
</div>
</body> 
</html>
4

0 回答 0