zencart里常用 SQL
1.如何替换某个字段的一些字符 如我把products表的products_image字段中包含2011的字符替换成Zencart2012 update `products` set `products_image`=replace(`products_image`,'2011','zencart2012'); 2.修改表的字段的长度 如我把products表的products_image字段长度修改为varchar(300) ALTER TABLE products MODIFY product_image varchar(256) ; 3.清空某个表的所有属性 如清空products表的所有数据信息 truncate TABLE products; 4.查询某个时间段订单,也可以自己扩展查询某个时间段的产品或者新闻 SELECT * FROM `orders` WHERE `date_purchased` BETWEEN '2010-05-22 00:00:00' AND '2012-02-01 00:00:00' order by orders_id desc 5.SQL组合查询,查询某个类别的商品 “select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, p.products_date_added, p.products_price, p.products_type, p.master_categories_id from ” . TABLE_PRODUCTS . ” p, ” . TABLE_PRODUCTS_DESCRIPTION . ” pd, where p.products_id = pd.products_id and p.products_id in(select products_id from ".TABLE_PRODUCTS_TO_CATEGORIES." where categories_id=你要显示的类别) and pd.language_id = ‘” . (int)$_SESSION['languages_id'] . “‘ and p.products_status = 1 ” . $display_limit 建议使用下面这种 “select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, p.products_date_added, p.products_price, p.products_type, p.master_categories_id from ” . TABLE_PRODUCTS . ” p, ” . TABLE_PRODUCTS_DESCRIPTION . ” pd,”. TABLE_PRODUCTS_TO_CATEGORIES . ” pc where p.products_id = pd.products_id and pc.categories_id in(54,55,62,67,61) and pd.language_id = ‘” . (int)$_SESSION['languages_id'] . “‘ and p.products_status = 1 ” . $display_limit 6.获取zencart所有分类下拉菜单的函数 zen_draw_pull_down_menu('selectoption', zen_get_category_tree(), array_pop($arr), 'id="list"'); |