私の検索スクリプトでは、次のコードの結果を得るのに問題があります:
$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>