我有这些mysql表,
-------------------------------------------------------------------
| products_id | date_added | date_modified |
| -----------------------------------------------------------------
| 1 | 2012-03-31 15:36:01 | 2012-5-03 00:00 |
| -----------------------------------------------------------------
| 2 | 2012-03-31 15:38:01 | 2012-5-04 00:00 |
| -----------------------------------------------------------------
| 3 | 2012-03-31 15:40:01 | NULL |
-------------------------------------------------------------------
我想根据选定的时间显示值,其中值不为空。
如果 date_modified 具有日期值,则使用 date_modified 作为其日期。如果它为 NULL,则使用 date_added 作为其日期。
if($_get['duration'] =="0") {
$duration = <select all regardless of date>;
}
elseif ($_get['duration'] =="24") {
$duration = <select all that less than 24 hours>;
}
elseif ($_get['duration'] =="15") {
$duration = <select all that less than 15 days>;
}
这是我的mysql查询,
$catglobal_sql = "select blog_id, global_category_id, products_id, products_currency, products_type, products_name, products_description, products_quantity, products_model, products_image, products_price, products_date_added, products_last_modified, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id, products_ordered, specials_new_products_price, specials_date_added, specials_last_modified, expires_date, date_status_change, status, display_product, case when (specials_new_products_price > 0 and expires_date > Now() and status != 0) then specials_new_products_price else products_price end price from " . TABLE_GLOBAL_PRODUCTS . " where products_name like '%" . $search_key . "%' and products_currency = '" . $currency_key . "' and display_product = '1' and products_status = '1' having price >= ".$pricefrom_key." and price <= ".$priceto_key." order by products_date_added DESC, products_name";
想不出解决办法。请帮忙。