初次对ecshop进行二次开发,可是一开始就遇到了乱码问题
我新增了一个函数,就是复制里面原有的函数,然后只改了SQL语句,其他都没有动
在模板页面里,当我用{$goods}这样循环输出传过来数组时,没有乱码,但是当我{$goods.name}这样输出数组中的指定键值时,就会出现乱码,不管值是中文或者英文,都会出现乱码。后台部分代码为:
function get_index_goods($cats = '',$num ='')
{
$time = gmtime();
$order_type = 0;
$sql = 'SELECT g.goods_id, g.is_index, g.goods_name, g.goods_name_style, g.et_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, " .
"g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " .
'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 ' .
" AND g.is_index = 1 ";
$sql .= $order_type == 0 ? ' ORDER BY g.goods_id desc' : ' ORDER BY rnd';
if($num != ''){
$sql .= " LIMIT $num ";
}
$result = $GLOBALS['db']->getAll($sql); $goods = array();
foreach ($result AS $idx => $row)
{
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]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$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]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']);
$goods[$idx]['et_price'] = price_format($row['et_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']);
}
return $goods;
}
$smarty->assign('index_goods', get_recommend_goods('index'));前台输出代码为(以下是没有乱码的):<!-- {foreach from=$index_goods item=indexgoods} -->
<!-- {foreach from=$indexgoods item=igoods key=key} -->
{$key}=>{$igoods}
<!-- {/foreach} -->
<!-- {/foreach} -->
我新增了一个函数,就是复制里面原有的函数,然后只改了SQL语句,其他都没有动
在模板页面里,当我用{$goods}这样循环输出传过来数组时,没有乱码,但是当我{$goods.name}这样输出数组中的指定键值时,就会出现乱码,不管值是中文或者英文,都会出现乱码。后台部分代码为:
function get_index_goods($cats = '',$num ='')
{
$time = gmtime();
$order_type = 0;
$sql = 'SELECT g.goods_id, g.is_index, g.goods_name, g.goods_name_style, g.et_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, " .
"g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " .
'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 ' .
" AND g.is_index = 1 ";
$sql .= $order_type == 0 ? ' ORDER BY g.goods_id desc' : ' ORDER BY rnd';
if($num != ''){
$sql .= " LIMIT $num ";
}
$result = $GLOBALS['db']->getAll($sql); $goods = array();
foreach ($result AS $idx => $row)
{
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]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$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]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']);
$goods[$idx]['et_price'] = price_format($row['et_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']);
}
return $goods;
}
$smarty->assign('index_goods', get_recommend_goods('index'));前台输出代码为(以下是没有乱码的):<!-- {foreach from=$index_goods item=indexgoods} -->
<!-- {foreach from=$indexgoods item=igoods key=key} -->
{$key}=>{$igoods}
<!-- {/foreach} -->
<!-- {/foreach} -->
{section name=ids loop=$ids_list}
<li><a href="">{$ids_list[ids]}</a></li>
{/section}