jim.davidson Posted April 30, 2007 Share Posted April 30, 2007 I'm running mySQL ver 4.1.21 with PHP and Dreamweaver I have three tables orders - customers – manufacturers Two variables $confirmation_id - $customer_id Need record set that contains orders.order_date orders.received_date orders.updated_date orders.received_by orders.destroyed_by orders.model_number orders.serial_number orders.capacity orders.confirmation_id customers.contact_name customers.contact_phone manufacturers.manufacture_name I get this error when I run my query: 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 'JOIN manufacturers on orders.manufacturer_id=manufacturers.manufacturer_id WHERE' at line 3 Here my query: SELECT orders.order_date, orders.received_date, orders.updated_date,orders.received_by,orders.destroyed_by,orders.model_number, orders.serial_number, orders.capacity, orders.confirmation_id, customers.contact_name, customers.contact_phone, manufacturers.manufacture_name FROM orders LEFT JOIN customers on orders.customer_id = $customer_id LEFT JOIN manufacturers on orders.manufacturer_id=manufacturers.manufacturer_id WHERE orders.confirmation_id =$confirmation_id", Any idea what I'm doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/49351-solved-query-using-left-join/ Share on other sites More sharing options...
jworisek Posted April 30, 2007 Share Posted April 30, 2007 LEFT JOIN customers on orders.customer_id = $customer_id you arent stating how customers should be joined... should probably be: LEFT JOIN customers on (orders.customer_id = customers.customer_id and customers.customer_id = $customer_id) Quote Link to comment https://forums.phpfreaks.com/topic/49351-solved-query-using-left-join/#findComment-241839 Share on other sites More sharing options...
jworisek Posted April 30, 2007 Share Posted April 30, 2007 actually, I would move the $customer_id clause to the where...like SELECT orders.order_date, orders.received_date, orders.updated_date,orders.received_by,orders.destroyed_by,orders.model_number, orders.serial_number, orders.capacity, orders.confirmation_id, customers.contact_name, customers.contact_phone, manufacturers.manufacture_name FROM orders LEFT JOIN customers on orders.customer_id = customers.customer_id LEFT JOIN manufacturers on orders.manufacturer_id=manufacturers.manufacturer_id WHERE orders.confirmation_id ='$confirmation_id' AND orders.customer_id = '$customer_id' Quote Link to comment https://forums.phpfreaks.com/topic/49351-solved-query-using-left-join/#findComment-241841 Share on other sites More sharing options...
jim.davidson Posted April 30, 2007 Author Share Posted April 30, 2007 Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/49351-solved-query-using-left-join/#findComment-241884 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.