我用的某多用户商城系统,现在想把店铺一级大类下面的二级类循环出来,同时二级大类下面自动读取当前二级大类中的推荐店铺,请问该怎么写。如下图:
代码如下:
$v){ $i++; ?> f $store){?> $store['store_id']),'store',$store['store_domain']);?> title= target=_blank> onload=javascript:drawimage(this,240,240); />
另外为什么不是从1开始?
回复讨论(解决方案) 你的代码不能实现吗?贴出 $output 的内容
$i++; 在 foreach($output['class_list'] as $k=>$v){ 循环中无条件执行
echo $i; 在 if ($_get['cate_id'] == $v['sc_parent_id']){ 分支中有条件执行
因为条件可能不成立,所以 echo $i;就可能不连续
既然 $i 表示一个顺号,那么就应该删除 9 行的 $i++;
而 14 行的 echo $i; 改为 echo ++$i;
$v){
$i++;
?>
除非这里只循环一次,你初始化$i=0,为什么会从1开始呢?
你的代码不能实现吗?贴出 $output 的内容
$i++; 在 foreach($output['class_list'] as $k=>$v){ 循环中无条件执行
echo $i; 在 if ($_get['cate_id'] == $v['sc_parent_id']){ 分支中有条件执行
因为条件可能不成立,所以 echo $i;就可能不连续
既然 $i 表示一个顺号,那么就应该删除 9 行的 $i++;
而 14 行的 echo $i; 改为 echo ++$i;
class shop_listcontrol extends basehomecontrol { /** * 店铺列表 */ public function indexop(){ /** * 读取语言包 */ language::read('home_store_class_index'); $lang = language::getlangcontent(); //店铺类目快速搜索 $class_list = ($h = f('store_class')) ? $h : h('store_class',true,'file'); if (!key_exists($_get['cate_id'],$class_list)) $_get['cate_id'] = 0; tpl::output('class_list',$class_list); //店铺搜索 $model = model(); $condition = array(); $keyword = trim($_get['keyword']); if(c('fullindexer.open') && !empty($keyword)){ //全文搜索 $condition = $this->full_search($keyword); }else{ if ($keyword != ''){ $condition['store_name|store_zy'] = array('like','%'.$keyword.'%'); } if ($_get['user_name'] != ''){ $condition['member_name'] = trim($_get['user_name']); } } if (!empty($_get['area_id'])){ $condition['area_id'] = array('in',$this->getareanextid(intval($_get['area_id']))); } if ($_get['cate_id'] > 0){ $child = array_merge((array)$class_list[$_get['cate_id']]['child'],array($_get['cate_id'])); $condition['sc_id'] = array('in',$child); } $condition['store_state'] = 1; if (!in_array($_get['order'],array('desc','asc'))){ unset($_get['order']); } if (!in_array($_get['key'],array('store_sales','store_credit'))){ unset($_get['key']); } if(is_null($_get['key'])){ $order = 'store_sort asc'; }else{ $order = $_get['key'].' '.$_get['order']; } if (isset($condition['store.store_id'])){ $condition['store_id'] = $condition['store.store_id'];unset($condition['store.store_id']); } $model_store = model('store');// $store_list = $model_store->where($condition)->order($order)->page(10)->select(); 20140408 bak $store_list = $model_store->where('store_recommend=1')->order($order)->page(10)->select(); //获取店铺商品数,推荐商品列表等信息 $store_list = $model_store->getstoresearchlist($store_list); tpl::output('store_list',$store_list); tpl::output('show_page',$model->showpage(2)); //当前位置 if (intval($_get['cate_id']) > 0){ $nav_link[1]['link'] = 'index.php?act=shop_list'; $nav_link[1]['title'] = $lang['site_search_store']; $nav =$class_list[$_get['cate_id']]; //如果有父级 if ($nav['sc_parent_id'] > 0){ $tmp = $class_list[$nav['sc_parent_id']]; //存入父级 $nav_link[] = array( 'title'=>$tmp['sc_name'], 'link'=>index.php?act=shop_list&cate_id=.$nav['sc_parent_id'] ); } //存入当前级 $nav_link[] = array( 'title'=>$nav['sc_name'] ); }else{ $nav_link[1]['link'] = 'index.php'; $nav_link[1]['title'] = $lang['homepage']; $nav_link[2]['title'] = $lang['site_search_store']; } tpl::output('nav_link_list',$nav_link); //seo model('seo')->type('index')->show(); tpl::output('html_title',(empty($_get['keyword']) ? '' : $_get['keyword'].' - ').c('site_name').$lang['nc_common_search']); tpl::showpage('shop_list'); }
你的代码不能实现吗?贴出 $output 的内容
$i++; 在 foreach($output['class_list'] as $k=>$v){ 循环中无条件执行
echo $i; 在 if ($_get['cate_id'] == $v['sc_parent_id']){ 分支中有条件执行
因为条件可能不成立,所以 echo $i;就可能不连续
既然 $i 表示一个顺号,那么就应该删除 9 行的 $i++;
而 14 行的 echo $i; 改为 echo ++$i;
$i 已经正常了,非常感谢。麻烦帮忙看看读取子分类下面推荐店铺该如何实现。偶是新手,还望海涵
你的代码不能实现吗?贴出 $output 的内容
$i++; 在 foreach($output['class_list'] as $k=>$v){ 循环中无条件执行
echo $i; 在 if ($_get['cate_id'] == $v['sc_parent_id']){ 分支中有条件执行
因为条件可能不成立,所以 echo $i;就可能不连续
既然 $i 表示一个顺号,那么就应该删除 9 行的 $i++;
而 14 行的 echo $i; 改为 echo ++$i;
我现在已经修改了 $store)的内容
$condition['store_state'] = 1;
$condition['store_recommend'] = 1;
$condition['sc_id'] = 66;
$store_list = $model_store->where($condition)->order($order)->page(10)->select();
现在可以读取sc_id=66的店铺,但是如何实现当前分类id获取,并筛选? 貌似能获取到当前分类的sc_id
你应该贴出 $output 的内容(至少需要完整的一节),并说明哪个要放在哪里
你应该贴出 $output 的内容(至少需要完整的一节),并说明哪个要放在哪里
下面的代码是模板文件的,如何将第一个循环中的$k值传递到第二个循环中的 $where .= $sc_id = $k; 件红色部分。
3楼我贴出的是php的处理文件
$v){
?>
f $k));?> style=max-width:90% target=_blank>更多..
$store){
$where .= $sc_id = $k;
?>
$store['store_id']),'store',$store['store_domain']);?> title= target=_blank>
onload=javascript:drawimage(this,240,240); />
要看到你的数据!
光看代码有什么用?如果代码就写错了呢
经验证上面的方法不行,
模板文件的代码是:
$v){ ?> f $k));?> style=max-width:90% target=_blank>更多.. $store){?> $store['store_id']),'store',$store['store_domain']);?> title= target=_blank> onload=javascript:drawimage(this,240,240); />
店铺搜索php的代码是
//店铺搜索 $model = model(); $condition = array(); $keyword = trim($_get['keyword']); if(c('fullindexer.open') && !empty($keyword)){ //全文搜索 $condition = $this->full_search($keyword); }else{ if ($keyword != ''){ $condition['store_name|store_zy'] = array('like','%'.$keyword.'%'); } if ($_get['user_name'] != ''){ $condition['member_name'] = trim($_get['user_name']); } } if (!empty($_get['area_id'])){ $condition['area_id'] = array('in',$this->getareanextid(intval($_get['area_id']))); } if ($_get['cate_id'] > 0){ $child = array_merge((array)$class_list[$_get['cate_id']]['child'],array($_get['cate_id'])); $condition['sc_id'] = array('in',$child); } $storeid=array($sid); $condition['store_state'] = 1; $condition['store_recommend'] = 1; if (!in_array($_get['order'],array('desc','asc'))){ unset($_get['order']); } if (!in_array($_get['key'],array('store_sales','store_credit'))){ unset($_get['key']); } if(is_null($_get['key'])){ $order = 'store_sort asc'; }else{ $order = $_get['key'].' '.$_get['order']; } if (isset($condition['store.store_id'])){ $condition['store_id'] = $condition['store.store_id'];unset($condition['store.store_id']); } $model_store = model('store');// $store_list = $model_store->where($condition)->order($order)->page(10)->select(); 20140408 bak $store_list = $model_store->where($condition)->order($order)->page(10)->select(); //获取店铺商品数,推荐商品列表等信息 $store_list = $model_store->getstoresearchlist($store_list); tpl::output('store_list',$store_list); tpl::output('show_page',$model->showpage(2));
麻烦帮忙看看如何循环出当前分类下的推荐店铺,现在的关键是如果将模板中第一个foreach的$k 传递到第二个foreach中进行筛选。筛选的关键代码是
$condition['store_state'] = 1;
$condition['store_recommend'] = 1;
查询是要按按显示的要求进行的
你只要打印出查询得到的最终数据,就可知道是否符合显示的要求
二次开发的话,可以调用系统栏目的函数啊,不用自己写
自己解决了,用了一个很笨的办法 用if进行判断!!代码如下:红色部分
$v){
?>
f 'shop_search','cate_id'=>$k));?> style=max-width:90% target=_blank>更多..
$store){?>
'show_store','id'=>$store['store_id']),'store',$store['store_domain']);?> title= target=_blank>
onload=javascript:drawimage(this,240,240); />
