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? 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. 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 Link to comment https://forums.phpfreaks.com/topic/246181-mysql-if/#findComment-1264330 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.