2013-03-20 67 views
0

例......即使「>」,大於選項被選中一個選擇不發佈所選選項

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> 
&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); 
+0

檢查您的形式被傳遞到正確的數據 - 你的價值觀可能會得到轉化成HTML實體 – andrewsi 2013-03-20 19:55:57

+0

這是被傳遞什麼陣列 ( [電路] => CIR1 [排序] => sr_id [子句] => => [排序順序] => ASC(6){[「circuits」] => string(4)「cir1」[「sorting」] => string(5)「sr_id」 [「clauses」] => string(2)「=>」[「sortorder」] => string(3)「asc」[「searchdb」] => string(3)「2.4」[「submit」] =>字符串(6)「搜索」} – bech64 2013-03-20 20:00:49

回答

1

這是因爲你在該行分號:

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

讓它

else if ($select2 == 'contain') 
+0

噢,我們在這裏有什麼......我沒有注意到。點! – Korcholis 2013-03-20 20:08:22

+0

那麼這是一個簡單的解決方法!我看了很多很多小時......額外的眼球總是幫助,這就是爲什麼我喜歡這個景象,很多非常有才華的人!你們是$ hizzle,謝謝你這麼多的幫助:) – bech64 2013-03-20 23:20:05

0

寫在你的search_new.php

var_dump($_POST); exit(); 

檢查值是多少clauses。我也想去另一個值的表示。我傾向於使用數字並將if/else結構減少到switch塊,但無論如何,您可以堅持。只是一個建議。而不是>,<和=,請使用「更大」,「更低」和「等於」或其他詞,因爲<和>是xml結構的一部分,您的瀏覽器可能會遇到問題。如果你檢查你寫的代碼塊,你會看到>實際上表現不佳。它被塗成黑色,而不是棕色/紅色。

綜上所述:

  • 檢查$_POST
  • 更改選項值,以數字或單詞,而不是符號的價值。
+0

嘗試更改符號單詞仍然在查詢中得到LIKE ... SELECT * FROM sr_rounds WHERE CIR1 LIKE'%2.4%'ORDER BY sr_id asc – bech64 2013-03-20 20:06:50

+0

and the change after,what's in'$ _POST'? – Korcholis 2013-03-20 20:07:44

1

你在你的代碼一個錯字:

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

此結束,如果塊。下一個{}塊總是執行。

+0

+1爲了解釋爲什麼最後一個塊總是被執行(我們所有的人的眼睛都集中在''like''條件而不是最後一個。 – Korcholis 2013-03-22 13:15:53

相關問題