Andy-H Posted September 1, 2011 Share Posted September 1, 2011 I'm trying to do a query with an if statement and an equality operator but it isn't working out too well, $db->query("SELECT p.id, CONCAT(p.branch_name, ' - ', (IF(o.fitting_date_info='fta', 'Fitter to arrange', DATE_FORMAT(o.fitting_date, '%a, %D %b @ %l:%i%p'))) AS title, f.latitude, f.longitude FROM premises p INNER JOIN ( orders o, order_addresses f ) ON ( o.prem_id = p.id AND o.fitting_address = f.id ) WHERE o.fitted = 0 AND o.fitting_info_updated > 2 ORDER BY o.order_id ASC"); Getting: Fatal error: Error with mysql query: SELECT p.id, CONCAT(p.branch_name, ' - ', (IF(o.fitting_date_info='fta', 'Fitter to arrange', DATE_FORMAT(o.fitting_date, '%a, %D %b @ %l:%i%p'))) AS title, f.latitude, f.longitude FROM premises p INNER JOIN ( orders o, order_addresses f ) ON ( o.prem_id = p.id AND o.fitting_address = f.id ) WHERE o.fitted = 0 AND o.fitting_info_updated > 2 ORDER BY o.order_id ASC You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM premises p INNER JOIN ( orders o, order_addresses f ) ON ( o.p' at line 2 in file C:\xampp\htdocs\classes\mysql.class.php on line 36 in C:\xampp\htdocs\classes\Error.class.php on line 6 [/size]I've had a little scan about and judging from tutorials I've seen it should work. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/246181-mysql-if/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2011 Share Posted September 1, 2011 You are missing the closing ) that goes with the opening one on the - CONCATE( Alternatively, you have an extra ( before the (IF that could be removed. Quote Link to comment https://forums.phpfreaks.com/topic/246181-mysql-if/#findComment-1264329 Share on other sites More sharing options...
Andy-H Posted September 1, 2011 Author Share Posted September 1, 2011 Lol missed that one Thanks PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/246181-mysql-if/#findComment-1264330 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.