广州传奇网络
地址:广州市天河区东圃大马路富华楼C座
电话:13808825895
QQ:1564443073
1、通过后台执行sq 执行
ALTER TABLE `ecs_goods` ADD `love` INT( 10 NULLLT '0';
在goods表添加一新的字段。
2、打开category.php找到category_get_goods 这个函数 把要显示的 love也给放进去。
/* 获得商品列表 */
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price,g.love, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' .
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " .
"WHERE $where $ext ORDER BY $sort $order";
$arr[$row['goods_id']]['love'] = $row['love'];
$arr[$row['goods_id']]['name'] = $row['goods_name'];
3、打开goods_list.lbi
<a href="javascript:;" onClick="change_love({$goods.goods_id})">喜欢</a><font id="show_loves_{$goods.goods_id}">{$goods.love} </font>
一定是在foreach循环里。
在这个lbi底部加
<script>
function change_love(goods_id)
{
var Lastsend = document.getCookie('ECS_auction_Lastsend_'+goods_id);
//alert(goods_id);
if(Lastsend == null)
{
Ajax.call( 'goods.php?act=chage_usenum','id=' + goods_id,chage_lovenum_Resp**e, 'POST', 'JSON');
document.setCookie('ECS_auction_Lastsend_'+goods_id,goods_id);
}
else
{
window.location.href='goods.php?id='+goods_id;
}
}
function chage_lovenum_Resp**e(result)
{
document.getElementById("show_loves_"+result.id).innerHTML = result.usenum;
}
</script>
4、打开goods.php
36行左右加入
if($_REQUEST['act']=='chage_usenum')
{
include('includes/cls_json.php');
$json = new JSON;
$res = array('err_msg' => '', 'result' => '', 'qty' => 1);
$id = $_REQUEST['id'];
$sql = $GLOBALS['db']->query("update ".$GLOBALS['ecs']->table('goods')." set love=love+1 where goods_id='$id'");
$res['id']= $id;
$res['usenum'] = $GLOBALS['db']->getOne("select love from ".$GLOBALS['ecs']->table('goods')." where goods_id='$id'");
die($json->encode($res));
}