我想在这个方法里多查询个分类名称。。
2016-07-07 16:15 来源:www.chinab4c.com 作者:ecshop专家
function get_category_recommend_goods($type = '', $cats = '', $brand = 0, $min =0,$max = 0, $ext='') { $brand_where = ($brand > 0) ? " AND g.brand_id = '$brand'" : ''; $price_where = ($min > 0) ? " AND g.shop_price >= $min " : ''; $price_where .= ($max > 0) ? " AND g.shop_price <= $max " : ''; $sql ='SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". 'promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . $brand_where . $price_where . $ext; $num = 0; $type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot', 'promote'=>'recommend_promotion'); $num = get_library_number($type2lib[$type]); switch ($type) { case 'best': $sql .= ' AND is_best = 1'; break; case 'new': $sql .= ' AND is_new = 1'; break; case 'hot': $sql .= ' AND is_hot = 1'; break; case 'promote': $time = gmtime(); $sql .= " AND is_promote = 1 AND promote_start_date <= '$time' AND promote_end_date >= '$time'"; break; } if (!empty($cats)) { $sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) .")"; } $order_type = $GLOBALS['_CFG']['recommend_order']; $sql .= ($order_type == 0) ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()'; $res = $GLOBALS['db']->selectLimit($sql, $num); $idx = 0; $goods = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } $goods[$idx]['id']= $row['goods_id']; $goods[$idx]['name']= $row['goods_name']; $goods[$idx]['brief']= $row['goods_brief']; $goods[$idx]['brand_name']= $row['brand_name']; $goods[$idx]['short_name']= $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price']= price_format($row['shop_price']); $goods[$idx]['thumb']= get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); $idx++; } return $goods; } 我改成这样了。。但是分类名称没出来是不是少改什么东西了? function get_category_recommend_goods($type = '', $cats = '', $brand = 0, $min =0,$max = 0, $ext='') { $brand_where = ($brand > 0) ? " AND g.brand_id = '$brand'" : ''; $price_where = ($min > 0) ? " AND g.shop_price >= $min " : ''; $price_where .= ($max > 0) ? " AND g.shop_price <= $max " : ''; $sql ='SELECT g.goods_id, g.cat_name, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". 'promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". "LEFT JOIN " . $GLOBALS['ecs']->table('category') ."AS ca ON ca.cat_id = g.cat_id" . 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . $brand_where . $price_where . $ext; $num = 0; $type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot', 'promote'=>'recommend_promotion'); $num = get_library_number($type2lib[$type]); switch ($type) { case 'best': $sql .= ' AND is_best = 1'; break; case 'new': $sql .= ' AND is_new = 1'; break; case 'hot': $sql .= ' AND is_hot = 1'; break; case 'promote': $time = gmtime(); $sql .= " AND is_promote = 1 AND promote_start_date <= '$time' AND promote_end_date >= '$time'"; break; } if (!empty($cats)) { $sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) .")"; } $order_type = $GLOBALS['_CFG']['recommend_order']; $sql .= ($order_type == 0) ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()'; $res = $GLOBALS['db']->selectLimit($sql, $num); $idx = 0; $goods = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } $goods[$idx]['id']= $row['goods_id']; $goods[$idx]['cat_name']= $row['cat_name']; $goods[$idx]['name']= $row['goods_name']; $goods[$idx]['brief']= $row['goods_brief']; $goods[$idx]['brand_name']= $row['brand_name']; $goods[$idx]['short_name']= $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price']= price_format($row['shop_price']); $goods[$idx]['thumb']= get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); $idx++; } return $goods; } |
回答:
有谁能帮帮我??? |
额。。。没人????我发错地方了?? |
怎么说呢,只能说楼主是一个很不细心的人(说话直接), 注意你改过的 $sql ='SELECT g.goods_id, g.cat_name, g.goods_name, g.goods_name_style, 应该是ca.cat_name 而不是 g.cat_name ecs_goods 这数据表里是没有cat_name 这个字段的, |
那个。。我用ca.cat_name 这个字段名也读不出来。。。 |
老大还在么???? |
function get_category_recommend_goods($type = '', $cats = '', $brand = 0, $min =0,$max = 0, $ext='') { $brand_where = ($brand > 0) ? " AND g.brand_id = '$brand'" : ''; $price_where = ($min > 0) ? " AND g.shop_price >= $min " : ''; $price_where .= ($max > 0) ? " AND g.shop_price <= $max " : ''; $sql ='SELECT g.goods_id, ca.cat_name, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". 'promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". "LEFT JOIN " . $GLOBALS['ecs']->table('category') ."AS ca ON ca.cat_id = g.cat_id" . 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . $brand_where . $price_where . $ext; $num = 0; $type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot', 'promote'=>'recommend_promotion'); $num = get_library_number($type2lib[$type]); switch ($type) { case 'best': $sql .= ' AND is_best = 1'; break; case 'new': $sql .= ' AND is_new = 1'; break; case 'hot': $sql .= ' AND is_hot = 1'; break; case 'promote': $time = gmtime(); $sql .= " AND is_promote = 1 AND promote_start_date <= '$time' AND promote_end_date >= '$time'"; break; } if (!empty($cats)) { $sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) .")"; } $order_type = $GLOBALS['_CFG']['recommend_order']; $sql .= ($order_type == 0) ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()'; $res = $GLOBALS['db']->selectLimit($sql, $num); $idx = 0; $goods = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } $goods[$idx]['id']= $row['goods_id']; $goods[$idx]['cat_name']= $row['cat_name']; $goods[$idx]['name']= $row['goods_name']; $goods[$idx]['brief']= $row['goods_brief']; $goods[$idx]['brand_name']= $row['brand_name']; $goods[$idx]['short_name']= $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price']= price_format($row['shop_price']); $goods[$idx]['thumb']= get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); $idx++; } return $goods; } 满意把... |
不行啊。。老大。还是没出来。 |
我发现了。。。 是{$goods.cat_name}读不出来。。。怎么办? |
有人帮帮我么???? |
查sql 里面是否有 cat_name |
最近更新
常用插件
- ecshop的oss插件
ecshop的oss插件免费共享了,oss,ecshoposs...
- ecshop没登陆情况下订单查
ecshop没登陆情况下订单查询插件,主要是针对ecshop在没有登陆的情况下...
- ecshop订单聚合插件
ecshop订单聚合插件,主要是为了方便ecshop中订单产品到货情况的分析和...
- ecshop虚拟发货插件
ecshop虚拟发货插件介绍: ecshop虚拟发货插件,主要为了通过后台手动录...
- ecshop注册审核插件
ecshop插件介绍:ecshop会员注册审核插件,主要是在前台提供给注册的时候...
ecshop热门问答
ecshop热门资料
ecshop恢复备份
ecshop显示市场价格
ecshopamazon
ecshop折扣价
ecshopshell
ecshopecs_goods
ecshop盛付通
ecshopCDMA手机
ecshopqq登录
ecshopupgrade
ecshop运营
ecshop文明
ecshop底部
ecshop飞入购物车
ecshop所有
ecshop北极星
ecshop单权限
ecshop选项卡
hair外贸模板
ecshop广告位
ecshop何故
ecshop敏感
ecshop增删改查
ecshop数据库表
ecshopLocroc
ecshomysqlrepair
ecshop来历不明
ecshop免费
ecshop系统自动登出
ecshop版块