Re: Complex MySQL query for lowest price
| From: | Jim Giner | Date: | Thu, 31 Jan 2013 19:40:12 +0000 |
| Subject: | Re: Complex MySQL query for lowest price | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-320133@lists.php.net to get a copy of this message | ||
On 1/31/2013 2:21 PM, Angela Barone wrote:
Hello, I have a formula that says, if 'specialprice' is not empty and it is lower than 'unitprice', use 'specialprice', otherwise use 'unitprice': <?php $result = mysql_query("SELECT LEAST(unitprice,ifnull(specialprice,'9999')) AS used_price FROM catalog WHERE itemid='WB1836C'",$db); printf('<b><font color="#555555">Your Price:</font> $%s</b><br />', number_format(mysql_result($result,0,"used_price"),2)); ?> What I'd like is to add a starting and ending date and if today's date is between those dates, then do the above formula, otherwise if today's date is not between those dates, then just use 'unitprice'. This is starting to get too complex for me, so I need some help. ;) Hopefully this makes sense. If I need to be clearer, please let me know. Thanks! Angela Have two queries and check the dates to determine which to use? (I'm assuming that the dates are NOT in the db)