示例...即使“>”也会显示此查询选择了大于选项
SELECT *
FROM sr_rounds
WHERE cir1 LIKE '%2.4%'
ORDER BY sr_id asc
有什么想法吗?
<form action="search_new.php" method="post" name="exchanges" id="exchanges">
<select name="circuits" id="circuits" onclick="searchIt()" onblur="searchIt()">
<option value="select" selected="selected">Select Search Field</option>
<option value="cir1">Circuit 1</option>
<option value="cir2">Circuit 2</option>
<option value="cir3">Circuit 3</option>
<option value="cir4">Circuit 4</option>
<option value="vch">VCH-1-5</option>
</select>
<select name="sorting" id="sorting" onclick="searchIt()" onblur="searchIt()">
<option value="select1" selected="selected">Sort By</option>
<option value="sr_id">Sector</option>
<option value="date">Date</option>
//This select always returns a "like" clause regardless of which option you select
</select>
<select name="clauses" id="clauses" onclick="searchIt()" onblur="searchIt()">
<option value="select2" selected="selected">Clause</option>
<option value="=">Equals</option>
<option value="like">Like</option>
<option value=">">Greater Than</option>
<option value="<">Less Than</option>
<option value="date">Date</option>
</select>
<select name="sortorder" id="sortorder" onclick="searchIt()" onblur="searchIt()">
<option value="select3" selected="selected">Order</option>
<option value="asc" name="1">Asc</option>
<option value="desc" name="2">Desc</option>
</select>
<?php
$select = $_POST['circuits'];
$searchdb = $_POST['searchdb'];
$select1 = $_POST['sorting'];
$select2 = $_POST['clauses'];
$select3 = $_POST['sortorder'];
//To display friendly field name instead of actual field name
if ($select == 'cir1')
{
$boxresult = 'Circuit 1';
}
if ($select == 'cir2')
{
$boxresult = 'Circuit 2';
}
if ($select == 'cir3')
{
$boxresult = 'Circuit 3';
}
if ($select == 'cir4')
{
$boxresult = 'Circuit 4';
}
if ($select == 'vch')
{
$boxresult = 'VCH-1-5';
}
//To use different queries while searching
if ($select2 == '=')
{
$queres = "SELECT * FROM sr_rounds WHERE $select = '$searchdb' ORDER BY $select1 $select3";
}
else if ($select2 == 'like')
{
$queres = "SELECT * FROM sr_rounds WHERE $select LIKE '$searchdb' ORDER BY $select1 $select3";
}
else if ($select2 == '>')
{
$queres = "SELECT * FROM sr_rounds WHERE $select > '$searchdb' ORDER BY $select1 $select3";
}
else if ($select2 == '<')
{
$queres = "SELECT * FROM sr_rounds WHERE $select < '$searchdb' ORDER BY $select1 $select3";
}
else if ($select2 == 'contain');
{
$queres = "SELECT * FROM sr_rounds WHERE $select LIKE '%$searchdb%' ORDER BY $select1 $select3";
}
$query = $queres;
$result = @mysql_query($query);
$num = @mysql_num_rows($result);
答案 0 :(得分:1)
您的代码中有拼写错误:
else if ($select2 == 'contain');
// ----------------------------^
这结束了if块。下一个{}
块始终执行。
答案 1 :(得分:1)
这是因为你在行中有一个分号:
else if ($select2 == 'contain');
成功
else if ($select2 == 'contain')
答案 2 :(得分:0)
在search_new.php
:
var_dump($_POST); exit();
检查clauses
值是多少。我还会再次代表价值观。我倾向于使用数字并将if/else
结构缩减为switch
块,但无论如何你都可以坚持使用。只是一个建议。而不是&gt;,&lt;和=,使用“更大”,“更低”和“等于”,或另一个词,如&lt;和&gt;是xml结构的一部分,浏览器可能存在一个问题。如果您检查了您编写的代码块,您会看到&gt;实际上表现不佳。它涂成黑色,而不是棕色/红色。
总结一下:
$_POST