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}
 
{$coms[sec1].cname|truncate:32:""}
诚聘:
{section name=sec2 loop=$coms[sec1].jobs}
{$coms[sec1].jobs[sec2].job|truncate:8:""}
{/section}
 
 {/section}

你可能感兴趣的:(php)