Problem: Looking up fields in products and products_description and looking up fields in categories and categories_description ...
There are two function in the functions_lookups that will pull any field that you need from the products or products_description tables by just passing it the products_id ... and for pulling any field from the categories and categories_description tables just by passing the categories_id ...
However there is an error in both of them that needs a minor fix ...
The original code for product lookup:
/includes/functions/functions_lookups.php
Code:
/*
* Return any field from products or products_description table
* Example: zen_products_lookup('3', 'products_date_added');
*/
function zen_products_lookup($product_id, $what_field = 'products_name', $language = '') {
global $db;
if (empty($language)) $language = $_SESSION['languages_id'];
$product_lookup = $db->Execute("select " . $what_field . " as lookup_field
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
where p.products_id ='" . (int)$product_id . "'
and pd.language_id = '" . (int)$language . "'");
$return_field = $product_lookup->fields['lookup_field'];
return $return_field;
}
The original code for category lookup :
/*
* Return any field from categories or categories_description table
* Example: zen_categories_lookup('10', 'parent_id');
*/
function zen_categories_lookup($categories_id, $what_field = 'categories_name', $language = '') {
global $db;
if (empty($language)) $language = $_SESSION['languages_id'];
$category_lookup = $db->Execute("select " . $what_field . " as lookup_field
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.categories_id ='" . (int)$categories_id . "'
and cd.language_id = '" . (int)$language . "'");
$return_field = $category_lookup->fields['lookup_field'];
return $return_field;
}
However, there is a little bug in these that you will want to update:
The new code for products look up:
Code:
/*
* Return any field from products or products_description table
* Example: zen_products_lookup('3', 'products_date_added');
*/
function zen_products_lookup($product_id, $what_field = 'products_name', $language = '') {
global $db;
if (empty($language)) $language = $_SESSION['languages_id'];
$product_lookup = $db->Execute("select " . $what_field . " as lookup_field
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
where p.products_id ='" . (int)$product_id . "'
and pd.products_id = p.products_id
and pd.language_id = '" . (int)$language . "'");
$return_field = $product_lookup->fields['lookup_field'];
return $return_field;
}
The new code for categories look up:
Code:
/*
* Return any field from categories or categories_description table
* Example: zen_categories_lookup('10', 'parent_id');
*/
function zen_categories_lookup($categories_id, $what_field = 'categories_name', $language = '') {
global $db;
if (empty($language)) $language = $_SESSION['languages_id'];
$category_lookup = $db->Execute("select " . $what_field . " as lookup_field
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.categories_id ='" . (int)$categories_id . "'
and c.categories_id = cd.categories_id
and cd.language_id = '" . (int)$language . "'");
$return_field = $category_lookup->fields['lookup_field'];
return $return_field;
}
Bookmarks