smarty嵌套循环

smarty嵌套循环实例详解

php代码
$d1=date('Y-m-d');
$sql="select distinct top 18 company.id,company.cname,company.uname,company.发布时间 from company inner join zp on zp.uname=company.uname where  zp.jzsj>='".$d1."' and zp.JOBSTATUS='00'  and company.qr='已审批' and company.yxsj>='".$d1."' order by  company.发布时间 desc";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res))
{
 $array[]= array("id"=>$row['id'],"cname"=>$row['cname']);
 $sql2="select top 3 id,job from zp where uname='".$row['uname']."' and jzsj>='".$d1."' and JOBSTATUS='00' order by sort,id asc";
 $res2 = $GLOBALS['db']->query($sql2);
 while ($row2 = $GLOBALS['db']->fetchRow($res2)){
  $jobs[]=array("job"=>$row2["job"],"id"=>$row2["id"]);
 }
 $com_ar[]=array("cname"=>$row["cname"],"id"=>$row["id"],"jobs"=>$jobs);
 unset($row2);
 unset($jobs);
}
$smarty->assign("coms",$com_ar);
unset($row);
unset($com_ar);
 
html代码
{section name=sec1 loop=$coms}
 <dl><dt><a href="zhaopincompany.php?id={$coms[sec1].id}" title="{$coms[sec1].cname}" target="_blank">{$coms[sec1].cname|truncate:32:""}</a></dt><dd>诚聘:
{section name=sec2 loop=$coms[sec1].jobs}
<a href='zhaopinjob.php?id={$coms[sec1].jobs[sec2].id}' target='_blank' title="{$coms[sec1].jobs[sec2].job}">{$coms[sec1].jobs[sec2].job|truncate:8:""}</a>、
{/section}
</dd></dl> 
 {/section}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值