我正在尝试为我正在构建的简单拍卖网站创建高级搜索系统。我希望有一个“Mozilla Thunderbird”#39;样式搜索系统,如果在表单中选择了某个选项,则会出现另一个表单,其中包含特定的选择选项,以便进行更窄的搜索。
对于那些不熟悉搜索系统的人,我已经附上了一张图片,希望有助于提供一些背景信息:
Mozilla Thunderbird Advanced Search
这是我到目前为止的代码:
<html>
<body>
<?php {
$servername = "";
$username = "";
$password = "";
$dbname ="";
$conn = new mysqli($servername, $username, $password, $dbname);
if($conn->connect_error) {
die("connection failed: " . $conn->connect_error);
}
$sql = "SELECT DISTINCT `category` FROM `iBayItems`";
$Category = $conn->query($sql);
if($Category->num_rows > 0) {
echo "<h2>Advanced Search</h2>
<p>Searching for items where: </p>";
/*First parameters*/
echo "<form action='TestAdvanced.php' method='POST'>
<select name='advancedSearch'>
<option value=''>Select Search...</option>
<option value='TitleSearch'>Title</option>
<option value='CategorySearch'>Category</option>
<option value='PriceSearch'>Price</option>
<option value='AddressSearch'>Address</option>
<option value='TimeLeftSearch'>Time Left</option>
</select>
</form>";
(isset($_POST["advancedSearch"])) ? $searchOption = $_POST["advancedSearch"] : $searchOption="";
/*Operators for first parameters*/
/*Title Operators*/
if ($searchOption == '') {
} else if ($searchOption == 'TitleSearch') {
echo "<form>
<select name='TitleOperators'>
<option value=''>Select Operator...</option>
<option value='LIKE'>is</option>
<option value='NOT LIKE'>is not</option>
</select>
</form>";
echo "<form>
<input type='text' required pattern='[A-Za-z0-9]{0,42}' name='Title'>
</form>";
} else if($searchOption == 'CategorySearch') {
/*Category Operators*/
echo "<form>
<select name='CategoryOperators'>
<option value=''>Select Operator...</option>
<option value='LIKE'>is</option>
<option value='NOT LIKE'>is not</option>
</select>
</form>";
echo "<form>
<select name='Category'>
<option value=''>Select Category...</option>";
while($row = $Category->fetch_assoc()) {
echo "<option value='";
echo $row["category"];
echo "' required>";
echo $row["category"];
echo "</option>";
}
echo "</select>
</form>";
} else if($searchOption == 'PriceSearch') {
/*Price Operators*/
echo "<form>
<select name='PriceOperators'>
<option value=''>Select Operator...</option>
<option value='='>equals</option>
<option value='<='>less than or equal to</option>
<option value='>='>greater than or equal to</option>
<option value='<'>less than</option>
<option value='>'>greater than</option>
</select>
</form>";
echo "<form>
<input type='number' required name='price' min='0' step='0.01'>
</form>";
} else if($searchOption == 'AddressSearch') {
/*Address Operators*/
echo "<form>
<select name='AddressOperators'>
<option value=''>Select Operator...</option>
<option value='LIKE'>near to</option>
<option value='NOT LIKE'>not near</option>
</select>
</form>";
echo "<form>
<input type='text' placeholder='E.g. NR18 9JJ' required name='postcode' pattern='[A-Za-z0-9]{0,42}'>
</form>";
} else if($searchOption == 'TimeLeftSearch') {
/*Time Operators*/
echo "<form>
<select name='TimeOperators'>
<option value=''>Select Operator...</option>
<option value='='>equals</option>
<option value='<='>less than or equal to</option>
<option value='>='>greater than or equal to</option>
<option value='<'>less than</option>
<option value='>'>greater than</option>
</select>
</form>";
echo "<form>
<input type='number' required name='days' min='0' step='1'>
<p> days</p>
</form>";
} ?>
</body>
</html>
我遇到的问题是让二级表格出现,我尝试使用&#34; noscript&#34;使用提交表单,但这并不是我真正需要的,因为我不希望每次选择一个选项时页面都会重新加载。
我对PHP很陌生,所以我试图通过研究,理解HTML和编码实践以及盲目运气来尽我所能。
到目前为止,我已使用这些链接来帮助我:
Using $_POST to get select option value from HTML
但是这些只是让我到目前为止。
从图片中可以看出,Thunderbird允许您进行多次搜索,在我解决了当前的问题后,我想自己实现这一点。
你能提供的任何帮助绝对太棒了!
亚历