2
---------------------------------------------------------------------------------------
| products_id | net_price | special_price | special_expire | special_status
| -------------------------------------------------------------------------------------
| 1 | 500 | 200 | 2012-5-03 00:00 | 1
| -------------------------------------------------------------------------------------
| 2 | 600 | 300 | 2012-6-04 00:00 | 0
| -------------------------------------------------------------------------------------
| 3 | 700 | 400 | 2012-7-05 00:00 | 1
---------------------------------------------------------------------------------------
凡,net_price
,special_price
,special_expire
是自我解釋和定義special_status
作爲1
應用特殊的價格和0
爲禁用特惠價。對MySQL表有條件選擇值
我有一個搜索表單,其中有一個價格範圍。
<form method="get" action="http://website.com">
<input type="text" id="ref-search" name="search" value="<?php echo $search_value;?>" class="text" size="55" placeholder="Type a keyword." style="height: 30px;
width: 89%;">
<label>Price Range:</label><br>
<span class="price-range">
From <input type="text" id="price1" name="pricefrom"
value="<?php echo $pricefrom_value; ?>" class="text" style="
height: 20px;
width: 22%;">
to <input type="text" id="price2" name="priceto"
value="<?php echo $priceto_value; ?>" class="text" style="
height: 20px;
width: 22%;">
</form>
我有一個很難開發或尋找解決有條件地選擇net_price
如果任special_price
是0.000
,則special_expire
日期值超過或special_status
的價值0
。然後,如果special_price
中有一個值,則special_expire
日期值未通過,並且special_status
的值爲1
,則請選擇special_price
值。
這是我想要的圖片。 (我知道這是不可能的,但是,我想這是對圖片我的問題的最好辦法。)
$sql = "select products_id, products_price, special_price, special_expire,
special_status, products_name from " . TABLE_GLOBAL_PRODUCTS . " where
products_name like '%" . $search_key . "%'
and /**Where the condition starts**/
if(special_value is =="0.000" || special_expire == <EXPIRED> ||
special_status =="0") {
products_price >= ".$pricefrom_key." and products_price <= ".$priceto_key."
} else {
specials_new_products_price >= ".$pricefrom_key."
and specials_new_products_price <= ".$priceto_key." order by products_name
}";
我希望你能幫助我的傢伙.. 謝謝。
工程就像一個魅力!謝謝你,先生!豎起大拇指! – Ken