我正在尝试让用户对他们希望搜索在其他方面进行排序以便于搜索,我正在寻找合适的方法将他们的选项(排序)传递给服务器。
这是我的html脚本
<form action="searchresult.php" method="post" id="searchengine" >
<div class="input-group" style="box-shadow: 0px 0px 15px 5px orange;border-radius: 20px">
<div class="input-group-btn">
<button class="btn dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="height: 35px;background-color:orange;color: white"><span class="fa fa-arrow-down"></span></button>
<ul name="searchmethod" class="dropdown-menu" style="background-color: orange;border:5px solid orange;margin-top: 10px;border-radius: 20px;padding:10px 5px;">
<li role="separator" class="divider"></li>
<li><input type="button" readonly="" style="padding:2px 4px;margin:2px 6px;height:26px;background-color: gold;width:270px;border:0px" class="btn" value="Search By Reviewee's Name"></li>
<li><input type="button" readonly="" style="padding:2px 4px;margin:5px 6px;height:26px;background-color: gold;width:270px" class="btn" value="Search By Reviewee's Website"></li>
<li><input type="button" readonly="" style="padding:2px 4px;margin:2px 6px;height:26px;background-color: gold;width:270px" class="btn" value="Search By Reviewer's Name"></li>
<li><input type="button" readonly="" style="padding:2px 4px;margin:2px 6px;height:26px;background-color: gold;width:270px" class="btn" value="Search By Review Date"></li>
<hr>
</ul>
</div>
<input type="text" class="form-control" name="word" style="width:190px;height:35px;background-color: #f3f558;font-size: 13px;color: black;padding-left:20px;padding-right:20px;text-align:center;font-family: cursive;" maxlength="40" required="" id="word" placeholder="Start Searching..." pattern="[a-Z0-9.,\']+" >
<span class="input-group-btn">
<button class="btn" style="height: 35px;background-color:orange;color: white" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</span>
</div>
</form>
,这是我的PHP脚本
<?php
//checks if the word and buttun are both available
if (!isset($_POST['word'])) {
die('get outta here');
}
//catches the word and stored in variable word
$word = sanitizeString($_POST['word']);
$_SESSION['recentsearch'] = $word;
$length = strlen($word);
if ($length <= 5) {
$newlength = ' ' . 'your search is too short, try a longer word ';
} elseif ($length > 5) {
$newlength = "";
}
if (isset($_POST['searchmethod'])) {
$searchMethod = $_POST['searchmethod'];
switch ($searchMethod) {
case "Search By Reviewee's Name":
$title = "Reviewee's name";
$searchMethod = 'reviewName';
break;
case "Search By Reviewee's Website":
$searchMethod = 'reviewLink';
$title = "Reviewee's Website Link ";
break;
case "Search By Reviewer's Name":
$searchMethod = 'reviewBy';
$title = "Reviewer's name ";
break;
case "Search By Review Date":
$searchMethod = 'reviewDate';
$title = "Review Date ";
break;
default:
$searchMethod = 'reviewName';
break;
}
} elseif (!isset($_POST['searchmethod'])) {
$searchMethod = 'reviewName';
$title = "Reviewee's name";
}
$search_exploded = explode(" ", $word);
$x = 0;
foreach ($search_exploded as $search_each) {
$x++;
$construct = "";
if ($x == 1) {
$construct .="$searchMethod LIKE '%$search_each%'";
} else {
$construct .="AND $searchMethod LIKE '%$search_each%'";
}
}
$construct = " SELECT * FROM reviews WHERE $construct ";
$result = mysqli_query($conn, $construct);
if (!$result->num_rows) {
echo 'Oops! No result found For ' . $title . ' (' . $word . ')' . $newlength;
}
if ($result->num_rows) {
$number = $result->num_rows;
echo ' ' . $number . ' Results Found Relating to ' . $title . ' (' . $word . '), Click
Here To See Results';
}
?>
问题是脚本无法将选项识别为帖子