var_dump($arr);
var_dump($arr1);都打印出来看看有数据吗

解决方案 »

  1.   

    楼主的代码问题不小,参考下面的代码吧:mysql_connect('localhost','root','root');
    mysql_select_db('test');
    mysql_query('set names gb2312');$result_uplei=mysql_query("select leiname from lei where uplei='0'");
    if($result_uplei){
    $i=0;
    while($row_uplei=mysql_fetch_row($result_uplei)){
    $result_sublei=mysql_query("select leiname from lei where uplei='{$row_uplei[0]}'");
    if($result_sublei)
    while($row_sublei=mysql_fetch_row($result_sublei))
    $sublei[]=$row_sublei[0];
    $uplei[]=array('leiname'=>$row_uplei[0],'sublei'=>$sublei);
    unset($sublei);
    }
    }require('smarty/Smarty.class.php');
    $smarty=new Smarty();
    $smarty->template_dir='./';
    $smarty->assign('uplei',$uplei);
    $smarty->display('lei.htm');{if $uplei}
    <ul>
    {foreach from=$uplei item=i}
    <li>{$i.leiname}
    {if $i.sublei}
    <dl>
    {foreach from=$i.sublei item=ii}
    <li>{$ii}</li>
    {/foreach}
    </dl>
    {/if}
    </li>
    {/foreach}
    </ul>
    {else}
    无分类
    {/if}
      

  2.   

    抛个砖,照楼主的改了改,
    不过不会用section,经常用foreach,未测试,呵呵
    希望对楼主有帮助。require "include/conndata.php";
    require "./classinclude.php";
    $rs=mysql_query("select * from lei where uplei='0'");    //找出一级分类
    $i=0;
    $num=mysql_num_rows($rs);
    while($i< mysql_num_rows($rs)){
    $arr=mysql_fetch_array($rs);
    $i++;
    $leiname=$arr["leiname"];

    $rows=mysql_query("select * from lei where uplei='$leiname'");
    $j=0;
        while($j < mysql_num_rows($rows))
    {
    $arr['subs']=mysql_fetch_array($rows);
    $leiname=$arr1["leiname"];
    //$smarty->assign("arr1",$arr1);
    $j++;
    }
        $smarty->append("arr",$arr);
    }
    $smarty->display("lei.html");{section name=key loop=$arr}
    <ul style="margin:0px;"><li><img src="image/jjbg.gif" />{$arr[key].leiname}</li>
        {section name=k loop=$arr[key].subs}
        <dl style="list-style-type:none; padding:5px;">
        <li style="margin:5px; margin-left:10px;">{$arr1[k].leiname}</li>
        </dl>
        {/section}   
    </ul>
    {/section}
      

  3.   

    tpl里{$arr1[k].leiname}是不是应该改成{$arr[key].subs[k].leiname}
    对section太迷糊了,呵呵
      

  4.   

    大概看了下 问题可能出在红色标记的地方<?php 
    require "include/conndata.php";
    require "./classinclude.php"; 
    $rs=mysql_query("select * from lei where uplei='0'"); //找出一级分类 $i=0; 
    $num=mysql_num_rows($rs); 
    while($i< mysql_num_rows($rs)){ 
      $arr=mysql_fetch_array($rs); 
      $i++; 
      $leiname=$arr["leiname"]; 
      $smarty->assign("arr",$arr); 
      $rows=mysql_query("select * from lei where uplei='$leiname'"); 
      $j=0; 
      while($j < mysql_num_rows($rows)) { 
        $arr1=mysql_fetch_array($rows); 
          $leiname=$arr1["leiname"]; 
            $smarty->assign("arr1",$arr1); 
            $j++; 
       } 

    $smarty->display("lei.html"); ?>因为smarty的section的接收参数 arr1是一个数组,你传进去的只是1个获得的值,现在的代码获取出来的就应该是 $arr1 => array(uplei=>"计算机科学" leiname=>"人体科学");这样的数组 然后你在smarty里再取 $arr1[0].leiname当然不对我觉得该
    $secondClassName = array();
      while($j < mysql_num_rows($rows)) { 
        $arr1=mysql_fetch_array($rows); 
          $leiname=$arr1["leiname"]; 
            $secondClassName [] = $ arr1;
            $j++; 
       } 

    $smarty->assign("arr1",$secondClassName);
    $smarty->display("lei.html");
    这样,小弟有什么说错的地方请各位指点。。
      

  5.   

    smarty中可以使用 $var|var_dump 把变量输出瞅瞅
      

  6.   

    问题还是出在基础没有打。
    有两个方面是:一是对二维数组的理解
                  二是对smarty的运行机制的理解。 php
    <?php
    require_once("./include/conndata.php");
    $rs=mysql_query("select * from lei where uplei='0'");    //找出一级分类
    if($rs){
    $i=0;
    $num=mysql_num_rows($rs);
    while($i< mysql_num_rows($rs)){
    $arr=mysql_fetch_array($rs);
    $i++;
    $leiname=$arr["leiname"];
    $rows=mysql_query("select * from lei where uplei='$leiname'");
    if($rows){
    $j=0;
    while($j < mysql_num_rows($rows))
       {
       $arr1=mysql_fetch_array($rows);
       $zilei=$arr1["leiname"];
       $lei["$leiname"][]=$zilei;
       $j++;
       }
    }
    }
    }
    require_once("./include.php");
    $smarty->assign("arr",$lei);
    $smarty->display("lei.html");
    ?>
    html:{foreach item=i from=$arr key=key}
    <ul style="margin:0px;"><li><img src="image/jjbg.gif" />{$key}</li>
    <dl style="list-style-type:none; padding:5px;">
    {foreach item=k from=$i}  
       <li style="margin:5px; margin-left:10px;">{$k}</li>
    {/foreach}  
     </dl>
    </ul>
    {/foreach}