Jump to content

MySQL IF


Andy-H

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.