Page 1 of 3 123 LastLast
Results 1 to 10 of 21
  1. #1
    Join Date
    Feb 2007
    Posts
    281
    Plugin Contributions
    0

    Default PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c'

    Any idea why i am getting this error? I searched hi and low for it and i did not see it happened with anyone else uses Zen Cart.

    [18-Jan-2025 06:20:33 UTC] Request URI: /index.php?main_page=index&manufacturers_id=8&sort=3a&page=2, IP address: x.x.13.12, Language id 1

    #0 [internal function]: zen_debug_error_handler()
    #1 /includes/classes/db/mysql/query_factory.php(733): trigger_error()
    #2 /includes/classes/db/mysql/query_factory.php(678): queryFactory->show_error()
    #3 /includes/classes/db/mysql/query_factory.php(307): queryFactory->set_error()
    #4 /includes/templates/responsive_classic/templates/tpl_index_product_list.php(46): queryFactory->Execute()
    #5 /includes/modules/pages/index/main_template_vars.php(232): require('/home/user/...')
    #6 /includes/templates/responsive_classic/common/tpl_main_page.php(181): require('/home/user/...')
    #7 /index.php(94): require('/home/user/...')
    --> PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c' :: SELECT p.products_image, pd.products_name, p.products_quantity, p.products_id, p.products_type, p.master_categories_id,
    p.manufacturers_id, p.products_price, p.products_tax_class_id, pd.products_description,
    IF(s.status = 1, s.specials_new_products_price, NULL) AS specials_new_products_price,
    IF(s.status = 1, s.specials_new_products_price, p.products_price) AS final_price,
    p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
    FROM products p
    LEFT JOIN specials s ON s.products_id = p.products_id
    LEFT JOIN products_description pd ON pd.products_id = p.products_id AND pd.language_id = 1
    LEFT JOIN manufacturers m ON m.manufacturers_id = p.manufacturers_id
    LEFT JOIN products_to_categories p2c ON p2c.products_id = p.products_id LEFT JOIN products_to_categories p2c ON p2c.products_id = p.products_id
    WHERE p.products_status = 1
    AND p.products_quantity > 0
    AND m.manufacturers_id = 8 AND p2c.categories_id = p.master_categories_id AND m.manufacturers_id = 8 AND p2c.categories_id = p.master_categories_id
    ORDER BY p.products_price_sorter , pd.products_name ==> (as called by) /includes/templates/responsive_classic/templates/tpl_index_product_list.php on line 46 <== in /includes/classes/db/mysql/query_factory.php on line 733.

  2. #2
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,616
    Plugin Contributions
    19

    Default Re: PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c'

    Quote Originally Posted by TamyA View Post
    Any idea why i am getting this error? I searched hi and low for it and i did not see it happened with anyone else uses Zen Cart.

    LEFT JOIN products_to_categories p2c ON p2c.products_id = p.products_id LEFT JOIN products_to_categories p2c ON p2c.products_id = p.products_id
    Your query is doubling the left join.
    Check the query here: /includes/modules/pages/index/main_template_vars.php and see if it's been modified and remove the double line, should be fine.

  3. #3
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,281
    Plugin Contributions
    125

    Default Re: PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c'

    Also check:

    includes/index_filters/default_filter.php
    includes/index_filters/YOUR_TEMPLATE/default_filter.php
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  4. #4
    Join Date
    Feb 2007
    Posts
    281
    Plugin Contributions
    0

    Default Re: PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c'

    Quote Originally Posted by balihr View Post
    Your query is doubling the left join.
    Check the query here: /includes/modules/pages/index/main_template_vars.php and see if it's been modified and remove the double line, should be fine.
    Thanks for the reply, The file was not edited, still the same file that was uploaded from zen cart 2.1.0

  5. #5
    Join Date
    Feb 2007
    Posts
    281
    Plugin Contributions
    0

    Default Re: PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c'

    Quote Originally Posted by swguy View Post
    Also check:

    includes/index_filters/default_filter.php
    includes/index_filters/YOUR_TEMPLATE/default_filter.php
    Thanks for the reply, This all the left join i found in includes/index_filters/default_filter.php and all of the is withen if else statment,
    so they should not be double lines, should they?

    This the code fro the file and the LEFT_JOIN in red
    // show the products of a specified manufacturer
    if (isset($_GET['manufacturers_id']) && $_GET['manufacturers_id'] > 0) {
    // We show them all
    $and .= " AND m.manufacturers_id = " . (int)$_GET['manufacturers_id'] . " ";
    if (isset($_GET['filter_id']) && zen_not_null($_GET['filter_id'])) {
    // We are asked to show only a specific category
    $sql_joins .= " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p2c.products_id = p.products_id ";
    $and .= " AND p2c.categories_id = " . (int)$_GET['filter_id'] . " ";
    } else {
    $sql_joins .= " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p2c.products_id = p.products_id ";
    $and .= ' AND p2c.categories_id = p.master_categories_id ';
    }
    } else {
    if (empty($and) && !empty($current_category_id)) {
    // show the products in a given category
    // We show them all
    $sql_joins .= " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p2c.products_id = p.products_id ";
    $and .= " AND p2c.categories_id = " . (int)$current_category_id . " ";
    }
    if (isset($_GET['filter_id']) && zen_not_null($_GET['filter_id'])) {
    // We are asked to show only specific category
    $and .= " AND m.manufacturers_id = " . (int)$_GET['filter_id'] . " ";
    }
    }
    .
    .
    .
    .
    // show the products of a specified manufacturer
    if (isset($_GET['manufacturers_id']) && $_GET['manufacturers_id'] > 0) {
    // We show them all
    $and .= " AND m.manufacturers_id = " . (int)$_GET['manufacturers_id'] . " ";
    if (isset($_GET['filter_id']) && zen_not_null($_GET['filter_id'])) {
    // We are asked to show only a specific category
    $sql_joins .= " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p2c.products_id = p.products_id ";
    $and .= " AND p2c.categories_id = " . (int)$_GET['filter_id'] . " ";
    } else {
    $sql_joins .= " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p2c.products_id = p.products_id ";
    $and .= ' AND p2c.categories_id = p.master_categories_id ';
    }
    } else {
    if (empty($and) && !empty($current_category_id)) {
    // show the products in a given category
    // We show them all
    $sql_joins .= " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p2c.products_id = p.products_id ";
    $and .= " AND p2c.categories_id = " . (int)$current_category_id . " ";
    }
    if (isset($_GET['filter_id']) && zen_not_null($_GET['filter_id'])) {
    // We are asked to show only specific category
    $and .= " AND m.manufacturers_id = " . (int)$_GET['filter_id'] . " ";
    }
    }



    the only thing was added in this file is code in red below

    $listing_sql .= $sql_joins ?? ' ';
    $where_str = "
    WHERE p.products_status = 1
    AND p.products_quantity > 0
    " . $and . "
    " . $alpha_sort;


    includes/index_filters/YOUR_TEMPLATE/default_filter.php, i do not have YOUR_TEPLATE under index_filters
    Last edited by TamyA; 18 Jan 2025 at 08:16 PM. Reason: more info

  6. #6
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,616
    Plugin Contributions
    19

    Default Re: PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c'

    Is this actually code that's in your default_filter.php file? Why is the same block of code doubled?

  7. #7
    Join Date
    Feb 2007
    Posts
    281
    Plugin Contributions
    0

    Default Re: PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c'

    Quote Originally Posted by balihr View Post
    Is this actually code that's in your default_filter.php file? Why is the same block of code doubled?
    Sorry, my mistake, it seems like when i edited the post to add more info i pasted the code again.

  8. #8
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,281
    Plugin Contributions
    125

    Default Re: PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c'

    @balihr: It's a bit confusing (especially to read unformatted) but I don't think the code is doubled, those should be mutually exclusive if/else blocks.

    @TamyA: Did you check the files I suggested?
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  9. #9
    Join Date
    Feb 2007
    Posts
    281
    Plugin Contributions
    0

    Default Re: PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c'

    Quote Originally Posted by swguy View Post
    @TamyA: Did you check the files I suggested?
    includes/index_filters/YOUR_TEMPLATE/default_filter.php
    There is no files in includes/index_filters/YOUR_TEMPLATE/default_filter.php
    since there are no directory /your _template/ inside include/index_filters


    the only thing was added in
    includes/index_filters/default_filter.php is the code in red below

    $listing_sql .= $sql_joins ?? ' ';
    $where_str = "
    WHERE p.products_status = 1
    AND p.products_quantity > 0
    " . $and . "
    " . $alpha_sort;

  10. #10
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,281
    Plugin Contributions
    125

    Default Re: PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c'

    Sorry, can't reproduce.
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

 

 
Page 1 of 3 123 LastLast

Similar Threads

  1. Search Header Box mysql Error on v1.5.7 (PHP Fatal error)
    By rlexyd in forum General Questions
    Replies: 4
    Last Post: 15 Jul 2021, 11:10 PM
  2. v156 PHP Fatal error: Uncaught Error: Class not found
    By Nick1973 in forum General Questions
    Replies: 7
    Last Post: 17 Apr 2020, 05:52 PM
  3. v156 PHP Fatal error: Uncaught Error: [] operator not supported for strings
    By chadlly2003 in forum General Questions
    Replies: 6
    Last Post: 6 Sep 2019, 01:37 AM
  4. v155 PHP Fatal error: mysql snatax please help
    By vapeshopmeuk in forum General Questions
    Replies: 4
    Last Post: 4 Jul 2019, 04:04 AM
  5. PHP Fatal error: 1062 Duplicate entry Error, cannot fix table
    By RoboPhung in forum General Questions
    Replies: 5
    Last Post: 10 Apr 2013, 09:03 PM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR