---------------------------------------------------------------------------------------
| 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
---------------------------------------------------------------------------------------
Where products_id, net_price, special_price, special_expire is self explanatory and special_status defines 1 as to apply the special price and 0 as to disable the special price.
I have a search form wherein there is a price range.
<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>
I’m having a hard time developing or finding a solution to conditionally select net_price if either special_price is 0.000, the special_expire date value has passed or the special_status‘s value is 0. Then if there is a value in the special_price, special_expire date value hasn’t passed and the special_status‘s value is 1 then select the special_price value.
This is the picture that i want to come from. ( I know that this is not possible but, i guess this is the best way to picture out my problem. )
$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
}";
I hope you can help me guys..
Thank you.
Try this:
Make sure you escape your inputs!