论坛风格切换
  • 4309阅读
  • 1回复

zen_get_manufacturers 函数解析 [复制链接]

上一主题 下一主题
ben
 

发帖
119
大洋
5222
贡献值
91
只看楼主 正序阅读 使用道具 楼主  发表于: 2011-08-06

zen_get_manufacturers($manufacturers_array = '', $have_products = false) 
该函数主要返回商品的生产厂家,返回一个包含厂家ID和名字的数组。默认返回所有的厂家信息, 
如果参数$have_products为true,则返回网站前台显示出来并且商品数量大于0的厂家信息。 
主要查询了 products和manufactrues 表。在includes/database_tables.php中定义: 
define('TABLE_PRODUCTS', DB_PREFIX . 'products'); 
define('TABLE_MANUFACTURERS', DB_PREFIX . 'manufacturers'); 
*/ 
函数源代码: 
function zen_get_manufacturers($manufacturers_array = '', $have_products = false) { 
    global $db; 
    if (!is_array($manufacturers_array)) $manufacturers_array = array(); 
 
    if ($have_products == true) { 
      $manufacturers_query = "select distinct m.manufacturers_id, m.manufacturers_name 
                              from " . TABLE_MANUFACTURERS . " m 
                              left join " . TABLE_PRODUCTS . " p on m.manufacturers_id = p.manufacturers_id 
                              where p.manufacturers_id = m.manufacturers_id 
                              and (p.products_status = 1 
                              and p.products_quantity > 0) 
                              order by m.manufacturers_name"; 
    } else { 
      $manufacturers_query = "select manufacturers_id, manufacturers_name 
                              from " . TABLE_MANUFACTURERS . " order by manufacturers_name"; 
    } 
 
    $manufacturers = $db->Execute($manufacturers_query); 
 
    while (!$manufacturers->EOF) { 
      $manufacturers_array[] = array('id' => $manufacturers->fields['manufacturers_id'], 'text' => $manufacturers->fields['manufacturers_name']); 
      $manufacturers->MoveNext(); 
    } 
 
    return $manufacturers_array; 
  } 

欢迎来到zen-cart论坛,这里将是你迈进zen-cart世界的起点
有问题到求助版块提问。
发帖
53
大洋
105
贡献值
1
只看该作者 沙发  发表于: 2012-03-12

快速回复
限80 字节
如果您在写长篇帖子又不马上发表,建议存为草稿。发帖请遵守版规(---删除纯表情和无意义内容,扣1分---)
 
上一个 下一个