Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2007
    Posts
    2
    Plugin Contributions
    0

    Default Adding new tables to the database

    Hi all
    I have added a table to the zen cart database called 'zen_products_kits'. The table has a products_id field as I need to link each entry to a particular product in the 'zen_products' table.

    I have been trying to edit includes\modules\pages\product_info\main_template_vars.php to pull in data from this new table. However I dont understand how to edit the query as the current query looks like the below. However the table in my database is called 'zen_products' yet the code uses 'TABLE_PRODUCTS' but pulls in the info form 'zen_products' Could some one please explain how this works?

    How would I write a query that also gets data from my new table called 'zen_products_kits'?

    Many Thanks
    Chris

    $sql = "select count(*) as total
    from " . TABLE_PRODUCTS . " p, " .
    TABLE_PRODUCTS_DESCRIPTION . " pd

    where p.products_status = '1'
    and p.products_id = '" . (int)$_GET['products_id'] . "'
    and pd.products_id = p.products_id
    and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";

  2. #2
    Join Date
    Sep 2004
    Location
    Western Massachusetts
    Posts
    2,945
    Plugin Contributions
    5

    Default Re: Adding new tables to the database

    The standard database table names are defined in includes/database_tables.php - that's how the cart knows that TABLE_PRODUCTS = zen_products.
    When adding a new table to the database, you need to give the cart a way of knowing what that table is - the normal way to do this is to create a new file and save it in the includes/extra_datafiles/ folder. So in your case, create a new file with this content
    Code:
    define('TABLE_PRODUCTS_KITS', DB_PREFIX . 'products_kits');
    and save it as includes/extra_datafiles/kits_database_names.php, (put a copy in admin/includes/extra_datafiles as well so you can access it from admin pages).
    Then your sql query can be modified to access that table, referring to it as TABLE_PRODUCTS_KITS
    Neville
    An assumption is what you arrive at when you get tired of thinking...

  3. #3
    Join Date
    Jan 2007
    Posts
    2
    Plugin Contributions
    0

    Default Re: Adding new tables to the database

    Many Thanks
    I will take a look at this

    Chris

 

 

Similar Threads

  1. Error importing old database to the new database
    By wmorris in forum Upgrading to 1.5.x
    Replies: 1
    Last Post: 3 Jan 2012, 08:27 AM
  2. Adding prefix to database tables
    By RyanKent in forum General Questions
    Replies: 3
    Last Post: 11 Sep 2011, 10:48 PM
  3. Adding a column to one of the database tables
    By sketchhgal in forum General Questions
    Replies: 15
    Last Post: 10 Jun 2010, 07:53 PM
  4. Create Database, Tables and Drop Database or Tables
    By elwood cordery in forum General Questions
    Replies: 3
    Last Post: 17 Aug 2009, 04:03 PM
  5. Replies: 2
    Last Post: 20 Feb 2009, 03:02 AM

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