这样写数据库为什么会查询出错?

2016-07-07 15:38 来源:www.chinab4c.com 作者:ecshop专家

为了能让首页显示商品的品牌,所以在 includes/lib_goods.php的288行的查询语句,添加了查询brand表但不知道怎么了就出问题了
高手能帮忙看下吗?
$sql = 'SELECT g.goods_id,g.goods_sn, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price,b.brand_name ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
"promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, RAND() AS rnd " .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b '.
"on g.brand_id = b.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]'";
$type_merge = array_merge($type_array['new'], $type_array['best'], $type_array['hot']);
$type_merge = array_unique($type_merge);
$sql .= ' WHERE g.goods_id ' . db_create_in($type_merge);
$sql .= ' ORDER BY g.sort_order, g.last_update DESC';

回答:
帮顶了……

建议换成双引号!