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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.