Forums / General Questions / Adding new tables to the database

Adding new tables to the database

Locked

Views: 1,923

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
1 Feb 2007, 4:21 PM
#1
christenn avatar

christenn

New Zenner

Join Date:
Jan 2007
Posts:
2
Plugin Contributions:
0

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'] . "'";
1 Feb 2007, 4:43 PM
#2
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

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 ```
define('TABLE_PRODUCTS_KITS', DB_PREFIX . 'products_kits');

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...

1 Feb 2007, 4:59 PM
#3
christenn avatar

christenn

New Zenner

Join Date:
Jan 2007
Posts:
2
Plugin Contributions:
0

Re: Adding new tables to the database

Many Thanks
I will take a look at this

Chris