Home > Backend Development > PHP Tutorial > thankphp里面双循环怎么写

thankphp里面双循环怎么写

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 14:18:06
Original
966 people have browsed it

$left_type = M('type')->where("`pid`='2'")->order('`order` desc,`id` desc')->limit(0,10)->select();	
Copy after login

foreach($left_type as $v){    $left_goods = M('goods')->where("`pid`='$v[id]'")->order('`order` desc,`id` desc')->limit(0,10)->select();}
Copy after login


大概意思就是有两个表,type表和goods表,type表是goods表的父级表,type表中的id字段对应goods表中的pid字段。
现在我想实现的是先把type表中的类别给循环出来,再在每个类别下面把相对应的goods表中的内容给循环出来。
但是之前没用过thankphp,不知道应该怎么写。最上面的那个肯定是错的,我就是写一下我的这个意思。

求大神随手写个demo我看下,谢谢了。


回复讨论(解决方案)

$result=M('goods')->join('RIGHT JOIN goods ON goods.pid = type.id')->select();
foreach($result as $key=>$v){
$value[$v['pid']][$key]['goodsname']=$v['goodsname'];
//...goods要取的内容
}


页面显示的话用两个volist循环可以搞定


$type_list = M("Type")->where()->order()->limit()->select();foreach($type_list as $key=>$val){   $type_list['items'] = M("Goods")->where("pid={$val['id']}")->select();}
Copy after login

<ul><volist name="type_list" id="vo"> <li>{$vo.title}     <ul>        <volist name="vo.items" id="it">           <li>{$it.name}</li>        </volist>     </ul> </li></volist></ul>
Copy after login

也许你是想要这个

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template