Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Location
    Huntington Beach, CA
    Posts
    55
    Plugin Contributions
    0

    Default Join records from the same table

    I am using ZenCart and have created a custom query for retrieving order data. The only problem is that when I have products with attributes it creates 2 records with the same order. This is because that each product gets a record for the attributes it gets.

    Here is my query:
    PHP Code:
    SELECT 
    zo
    .orders_id as v_orders_id,
    customers_id as v_customers_id,
    customers_name as v_customers_name,
    customers_company as v_customers_company,
    customers_street_address as v_customers_street_address,
    customers_suburb as v_customers_suburb,
    customers_city as v_customers_city,
    customers_postcode as v_customers_postcode,
    customers_country as v_customers_country,
    customers_telephone as v_customers_telephone,
    customers_email_address as v_customers_email_address,
    date_purchased as v_date_purchased,
    orders_status_name as v_orders_status_name,
    products_model as v_products_model,
    products_id as v_products_id,
    products_name as v_products_name,
    products_options as v_products_options,
    products_options_values as v_products_options_values
    FROM 
    ".TABLE_ORDERS_PRODUCTS." zop LEFT JOIN ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES." opa
    ON
    (zop.orders_products_id opa.orders_products_id), ".TABLE_ORDERS." zo".TABLE_ORDERS_STATUS." zos
    WHERE zo
    .orders_id zop.orders_id
    AND zop.orders_id BETWEEN '1' AND '800'
    AND zo.orders_status zos.orders_status_id
    AND zop.products_id '147' 
    I need to have all of the results for the specific product end up on the same line in my export. How can I accomplish this?

    Thanks in advance!
    Rob
    Pier Marketing ◄ Printing and Marketing Collateral - Order Online!
    Pier Technologies ◄ Web Development & IT Solutions
    And That's News? ◄ My NEW Blog!!

  2. #2
    Join Date
    Jun 2006
    Location
    Huntington Beach, CA
    Posts
    55
    Plugin Contributions
    0

    Default Re: Join records from the same table

    I am using a class that helps me output the following
    PHP Code:
    <table>
    &
    #8722;
        
    <ROW>
    <
    V_ORDERS_ID>796</V_ORDERS_ID>
    <
    V_CUSTOMERS_ID>509</V_CUSTOMERS_ID>
    <
    V_CUSTOMERS_NAME>rob milburn</V_CUSTOMERS_NAME>
    <
    V_CUSTOMERS_COMPANY/>
    <
    V_CUSTOMERS_STREET_ADDRESS>2511 florida</V_CUSTOMERS_STREET_ADDRESS>
    <
    V_CUSTOMERS_SUBURB>5</V_CUSTOMERS_SUBURB>
    <
    V_CUSTOMERS_CITY>huntington beach</V_CUSTOMERS_CITY>
    <
    V_CUSTOMERS_POSTCODE>92648</V_CUSTOMERS_POSTCODE>
    <
    V_CUSTOMERS_COUNTRY>United States</V_CUSTOMERS_COUNTRY>
    <
    V_CUSTOMERS_TELEPHONE>714-849-3124</V_CUSTOMERS_TELEPHONE>
    <
    V_CUSTOMERS_EMAIL_ADDRESS>rob@piermarketing.com</V_CUSTOMERS_EMAIL_ADDRESS>
    <
    V_DATE_PURCHASED>2008-02-29 13:29:55</V_DATE_PURCHASED>
    <
    V_ORDERS_STATUS_NAME>Processing</V_ORDERS_STATUS_NAME>
    <
    V_PRODUCTS_MODEL/>
    <
    V_PRODUCTS_ID>147</V_PRODUCTS_ID>
    <
    V_PRODUCTS_NAME>Business Cards</V_PRODUCTS_NAME>
    <
    V_PRODUCTS_OPTIONS>Name</V_PRODUCTS_OPTIONS>
    <
    V_PRODUCTS_OPTIONS_VALUES>rob milburn</V_PRODUCTS_OPTIONS_VALUES>
    </
    ROW>
    &
    #8722;
        
    <ROW>
    <
    V_ORDERS_ID>796</V_ORDERS_ID>
    <
    V_CUSTOMERS_ID>509</V_CUSTOMERS_ID>
    <
    V_CUSTOMERS_NAME>rob milburn</V_CUSTOMERS_NAME>
    <
    V_CUSTOMERS_COMPANY/>
    <
    V_CUSTOMERS_STREET_ADDRESS>2511 florida</V_CUSTOMERS_STREET_ADDRESS>
    <
    V_CUSTOMERS_SUBURB>5</V_CUSTOMERS_SUBURB>
    <
    V_CUSTOMERS_CITY>huntington beach</V_CUSTOMERS_CITY>
    <
    V_CUSTOMERS_POSTCODE>92648</V_CUSTOMERS_POSTCODE>
    <
    V_CUSTOMERS_COUNTRY>United States</V_CUSTOMERS_COUNTRY>
    <
    V_CUSTOMERS_TELEPHONE>714-849-3124</V_CUSTOMERS_TELEPHONE>
    <
    V_CUSTOMERS_EMAIL_ADDRESS>rob@piermarketing.com</V_CUSTOMERS_EMAIL_ADDRESS>
    <
    V_DATE_PURCHASED>2008-02-29 13:29:55</V_DATE_PURCHASED>
    <
    V_ORDERS_STATUS_NAME>Processing</V_ORDERS_STATUS_NAME>
    <
    V_PRODUCTS_MODEL/>
    <
    V_PRODUCTS_ID>147</V_PRODUCTS_ID>
    <
    V_PRODUCTS_NAME>Business Cards</V_PRODUCTS_NAME>
    <
    V_PRODUCTS_OPTIONS>Address</V_PRODUCTS_OPTIONS>
    <
    V_PRODUCTS_OPTIONS_VALUES>2511 florida</V_PRODUCTS_OPTIONS_VALUES>
    </
    ROW>
    </
    table
    Now I just need to figure out how to combine this line <V_PRODUCTS_OPTIONS_VALUES> becuase as it is now, this is jsut the 1 order, but since there are multiple <V_PRODUCTS_OPTIONS_VALUES> it creates new records for each instance.

    Any ideas?
    Rob
    Pier Marketing ◄ Printing and Marketing Collateral - Order Online!
    Pier Technologies ◄ Web Development & IT Solutions
    And That's News? ◄ My NEW Blog!!

 

 

Similar Threads

  1. Replies: 4
    Last Post: 13 Nov 2016, 11:03 PM
  2. Replies: 9
    Last Post: 27 Jul 2010, 09:54 PM
  3. WARNING: The Admin Activity Log table has records over 2 months old and...
    By Agent_KGB in forum Customization from the Admin
    Replies: 1
    Last Post: 28 Mar 2009, 04:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg