一个选择不会发布所选选项

Example... this query is displayed even though the ">" Greater Than option was selected

SELECT * 
FROM sr_rounds 
WHERE cir1 LIKE '%2.4%' 
ORDER BY sr_id asc

Any ideas?

<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>
&nbsp;
<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);

It is because you have a semi-colon in the line:

else if ($select2 == 'contain');

Make it

else if ($select2 == 'contain')

write this in your search_new.php:

var_dump($_POST); exit();

Check what clauses value is. I'd also go for another representation of the values. I tend to use numbers and reduce the if/else structure to a switch block, but anyway you can stick to whatever. Just an advice. Instead of >, < and =, use "greater", "lower" and "equals", or another word, as < and > are part of the xml structure, and there may be a problem for your browser to understand that. If you check the codeblock you wrote, you will see that the > is actually not acting well. It's painted black, instead of brown/red.

To sum up:

  • Check the value of $_POST
  • Change the option values to numbers or words, not symbols.

You have a typo in your code:

else if ($select2 == 'contain');
// ----------------------------^

This ends the if block. The next {} block executes always.