My problem is extracting the order with the proper attributes associated with it I'm going to save it in a .CSV file to be processed offline in our existing systems.

*credit card#s removed* :)
http://www.shopnorthern.anthony.ca/temp/getpayment5.php

I can't seem to limit the attributes associated with the product TO THAT product. Basically, if the item has attributes, my SQL statement is going to retreive all the attributes "turned on" for that order. In ORDER ID 2, you can see that both the SAUNA BELT and the LADDER have the payment plan. (only the ladder should have the payment plan).

I guess my problem is, I can't find the correct fields in orders_products_attributes that would limit it just to that particular product that was ordered.


Here are the SQL statements I'm using:
---------------------------------------------

STEP 1: Retrieve the orders:
$query = "SELECT * FROM orders ";

STEP 2: Get the list of products ordered:
$query = "SELECT * FROM orders_products WHERE orders_id= " . $order_id . " ";

STEP 3a: Check to see if there is an attribute associated with this product:
$query = "SELECT products_attributes_id FROM products_attributes WHERE products_id = " . $products_id . " ";


STEP 3b: If there is an attribute for this product GET IT:
$query = "SELECT * FROM orders_products_attributes WHERE orders_id = " . $order_id . " ";

------------------------------

Thanks for your help!