Jump to content

[SOLVED] query using left join


jim.davidson

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/49351-solved-query-using-left-join/
Share on other sites

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'

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.