这是ecshop手机端的index模板的一段代码
define('in_ecs', true);require(dirname(__file__) . '/includes/init.php');$type = !empty($_get['type']) ? $_get['type'] : 'best';if ($type != 'best' && $type != 'promote' && $type != 'hot' && $type != 'new'){ $type = 'best';}$smarty->assign('type', $type);if (empty($_get['order_price'])){ $order_rule = 'order by shop_price asc, g.last_update desc';}else{ $order_rule = 'order by shop_price desc, g.last_update desc';}if ($type == 'promote'){ $goods = wap_get_promote_goods($order_rule);}else{ $goods = wap_get_recommend_goods($type, $order_rule);}$num = count($goods);if ($num > 0){ foreach ($goods as $key => $data) { $sort_array[$data['id']] = $key; } $page_num = '10'; $page = !empty($_get['page']) ? intval($_get['page']) : 1; $pages = ceil($num / $page_num); if ($page $pages) { $page = $pages; } $i = 1; foreach ($sort_array as $goods_key) { if (($i > ($page_num * ($page - 1 ))) && ($i $i , 'price' => encode_output($price) , 'id' => $goods[$goods_key]['id'] , 'name' => encode_output($goods[$goods_key]['name']), 'thumb' => $goods[$goods_key]['thumb']);//16:43 2013-07-16 } $i++; } $smarty->assign('goods_data', $goods_data); $pagebar = get_wap_pager($num, $page_num, $page, 'goods_list.php?type='.$type.'&order_price='.(empty($order_price)?0:$order_price), 'page'); $smarty->assign('pagebar' , $pagebar);}$smarty->assign('footer', get_footer());$smarty->display('goods_list.html');function wap_get_recommend_goods($type = '', $order_rule = ''){ if (!in_array($type, array('best', 'new', 'hot'))) { return array(); } //取不同推荐对应的商品 static $type_goods = array(); if (empty($type_goods[$type])) { //初始化数据 $type_goods['best'] = array(); $type_goods['new'] = array(); $type_goods['hot'] = array(); $data = read_static_cache('recommend_goods'); if ($data === false) { $sql = 'select g.goods_id, g.is_best, g.is_new, g.is_hot, g.is_promote, b.brand_name,g.sort_order ' . ' from ' . $globals['ecs']->table('goods') . ' as g ' . ' left join ' . $globals['ecs']->table('brand') . ' as b on b.brand_id = g.brand_id ' . ' where g.is_on_sale = 1 and g.is_alone_sale = 1 and g.is_delete = 0 and (g.is_best = 1 or g.is_new =1 or g.is_hot = 1)'. ' order by g.sort_order, g.last_update desc'; $goods_res = $globals['db']->getall($sql); //定义推荐,最新,热门,促销商品 $goods_data['best'] = array(); $goods_data['new'] = array(); $goods_data['hot'] = array(); $goods_data['brand'] = array(); if (!empty($goods_res)) { foreach($goods_res as $data) { if ($data['is_best'] == 1) { $goods_data['best'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']); } if ($data['is_new'] == 1) { $goods_data['new'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']); } if ($data['is_hot'] == 1) { $goods_data['hot'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']); } if ($data['brand_name'] != '') { $goods_data['brand'][$data['goods_id']] = $data['brand_name']; } } } write_static_cache('recommend_goods', $goods_data); } else { $goods_data = $data; } $time = gmtime(); $order_type = $globals['_cfg']['recommend_order']; static $type_array = array(); $type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot'); if (empty($type_array)) { foreach($type2lib as $key => $data) { if (!empty($goods_data[$key])) { $data_count = count($goods_data[$key]); $num = $data_count ; if ($order_type == 0) { //usort($goods_data[$key], 'goods_sort'); $rand_key = array_slice($goods_data[$key], 0, $num); foreach($rand_key as $key_data) { $type_array[$key][] = $key_data['goods_id']; } } else { $rand_key = array_rand($goods_data[$key], $num); if ($num == 1) { $type_array[$key][] = $goods_data[$key][$rand_key]['goods_id']; } else { foreach($rand_key as $key_data) { $type_array[$key][] = $goods_data[$key][$key_data]['goods_id']; } } } } else { $type_array[$key] = array(); } } } //取出所有符合条件的商品数据,并将结果存入对应的推荐类型数组中 $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, g.goods_img, rand() as rnd . '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]' ; $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); $order_rule = empty($order_rule) ? ' order by g.sort_order, g.last_update desc' : $order_rule; $sql .= $order_rule; $result = $globals['db']->getall($sql); 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'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : ''; $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]['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']); if (in_array($row['goods_id'], $type_array['best'])) { $type_goods['best'][] = $goods[$idx]; } if (in_array($row['goods_id'], $type_array['new'])) { $type_goods['new'][] = $goods[$idx]; } if (in_array($row['goods_id'], $type_array['hot'])) { $type_goods['hot'][] = $goods[$idx]; } } } return $type_goods[$type];}function wap_get_promote_goods($order_rule = ''){ $time = gmtime(); /* 取得促销lbi的数量限制 */ $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, . 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_promote = 1 and promote_start_date = '$time' ; $order_rule = empty($order_rule) ? 'order by g.sort_order, g.last_update desc' : $order_rule; $sql .= $order_rule; $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]['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']); } return $goods;}
这是业务代码,为什么index模板的$new_num会为0没有数据?
回复讨论(解决方案) 代码不完整,都没看到调用模版的代码。
我在index.php改好了 谢谢